Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Rounding Timestamp to nearest hour
Tue, Oct 8 2013 2:33 PMPermanent Link

Rolf Nilsson

Hi,
I have a generated Integer column where I try to calculate
number of hours from two Timestamp columns like this:

ALTER COLUMN "TimeCount" AS INTEGER GENERATED ALWAYS AS CAST((Date2 - Date1) AS INTERVAL HOUR)

This works, but now I have to round the result to nearest hour, something like this:

ALTER COLUMN "TimeCount" AS INTEGER GENERATED ALWAYS AS ROUND(CAST((Date2 - Date1) AS INTERVAL MINUTE) / 60)

This doesn't work obviously.
any advice is most Welcome.

Best regards,
Rolf
Tue, Oct 8 2013 5:43 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Rolf,

<< ALTER COLUMN "TimeCount" AS INTEGER GENERATED ALWAYS AS
ROUND(CAST((Date2 - Date1) AS INTERVAL MINUTE) / 60)

This doesn't work obviously.  >>

Use this:

ALTER COLUMN "TimeCount" AS INTEGER GENERATED ALWAYS AS
ROUND(CAST(CAST((Date2 - Date1) AS INTERVAL MINUTE) AS INTEGER) / 60)

Tim Young
Elevate Software
www.elevatesoft.com


Wed, Oct 9 2013 7:54 AMPermanent Link

Rolf Nilsson

On 2013-10-08 23:43, Tim Young [Elevate Software] wrote:
> Use this:
>
> ALTER COLUMN "TimeCount" AS INTEGER GENERATED ALWAYS AS
> ROUND(CAST(CAST((Date2 - Date1) AS INTERVAL MINUTE) AS INTEGER) / 60)


Thanks Tim, that did it!
By the way, Intervals is not easy to understand. Would be nice
with a good educational article on the subject
Thu, Oct 10 2013 3:22 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Rolf,

<< By the way, Intervals is not easy to understand. Would be nice with a
good educational article on the subject >>

Yes, definitely.  I hope to get some time to start adding some more
technical articles soon.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Image