Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Error in Timestamp calculation.
Mon, Feb 20 2012 11:23 PMPermanent Link

Mark Gibson

Hi Folks,

I'm getting a very strange error when adding days to a timestamp using the following SQL:

INSERT INTO table1
VALUES((CURRENT_TIMESTAMP + (24 * 86400000)))

This works fine with any number up to 24. If I change the number of days to add to 25 or higher the returned timestamp is wrong.

Adding 24 days to now gives me 16/03/2012 3:19:11 PM (formatted to Australian date ie dd/mm/yy)

Adding 25 days gives me 27/01/2012 10:17:50 PM instead of 17/03/2012 10:17:50 PM

Any idea what to problem might be?

Thanks in advance, Mark Gibson
Mon, Feb 20 2012 11:27 PMPermanent Link

Mark Gibson

Whoops, should have added it is Version 4.30 (4.30 Build 7)
Tue, Feb 21 2012 2:53 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Mark


I guessing that you're exceeding a data type size somewhere, probably the integer you're generating by multiplying days and milliseconds a day and its wrapping round.

Its a bit cludgey but try

CAST(
CAST((CURRENT_DATE+25) AS VARCHAR(10))
+' '+
CAST(CURRENT_TIME AS VARCHAR(8))
AS TIMESTAMP)


Roy Lambert [Team Elevate]
Tue, Feb 21 2012 6:53 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Mark,

<< I'm getting a very strange error when adding days to a timestamp using
the following SQL: >>

Raul is 100% correct - you've got an Integer wrapping issue. Use this SQL
instead:

INSERT INTO table1
VALUES((CURRENT_TIMESTAMP + (25 * CAST(86400000 AS LARGEINT))))

--
Tim Young
Elevate Software
www.elevatesoft.com
Tue, Feb 21 2012 3:06 PMPermanent Link

Mark Gibson

Thanks so much guys, I'll give this a try after work tonight.

Cheers, Mark

"Tim Young [Elevate Software]" wrote:

Mark,

<< I'm getting a very strange error when adding days to a timestamp using
the following SQL: >>

Raul is 100% correct - you've got an Integer wrapping issue. Use this SQL
instead:

INSERT INTO table1
VALUES((CURRENT_TIMESTAMP + (25 * CAST(86400000 AS LARGEINT))))

--
Tim Young
Elevate Software
www.elevatesoft.com
Image