Author |
Message
|
dean |
Posted: Wed Aug 12, 2009 10:39 am Post subject: converting from a timestamp to epoch time |
|
|
Novice
Joined: 29 May 2009 Posts: 15
|
This works going from epoch to a timestamp:
SET HrTmStmpSec = TIMESTAMP '1970-01-01 00:00:00' + CAST(InputRoot.MRM.cstdatestamp AS INTERVAL SECOND);
How would I do the reverse -- convert from a timestamp to seconds since 1/1/1970?
Thanks,
Dean |
|
Back to top |
|
 |
nagarjun_vv |
Posted: Wed Aug 12, 2009 11:49 pm Post subject: |
|
|
Apprentice
Joined: 24 Jun 2008 Posts: 33
|
to find the difference between two timestamp use this code
(TIMESTAMP '2009-08-13 15:44:00' - TIMESTAMP '1999-08-13 15:44:00') SECOND
Regards,
Nagarjun. |
|
Back to top |
|
 |
dean |
Posted: Thu Aug 13, 2009 4:48 am Post subject: invalid characters error |
|
|
Novice
Joined: 29 May 2009 Posts: 15
|
thanks for the reply. I'm getting the following error trying to use your suggestion. Any ideas?
DECLARE HrTmStmpSec INTEGER (TIMESTAMP '2009-06-16 14:18:23' - TIMESTAMP '1970-01-01 00:00:00') SECOND;
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'DECLARE HrTmStmpSec INTEGER TIMESTAMP '2009-06-16 14:18:23' - TIMESTAMP '1970-01-01 00:00:00';' (CHARACTER)
)
(0x01000000:Name ):ConversionException = (
(0x03000000:NameValue):File = '/build/S610_P/src/CommonServices/ImbUtility.cpp' (CHARACTER)
(0x03000000:NameValue):Line = 436 (INTEGER)
(0x03000000:NameValue):Function = 'imbWcsToInt64' (CHARACTER)
(0x03000000:NameValue):Type = '' (CHARACTER)
(0x03000000:NameValue):Name = '' (CHARACTER)
(0x03000000:NameValue):Label = '' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPv610' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 2595 (INTEGER)
(0x03000000:NameValue):Text = 'Invalid characters' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'INTERVAL '1245161903' SECOND' (CHARACTER) |
|
Back to top |
|
 |
mgk |
Posted: Thu Aug 13, 2009 7:02 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
You need to CAST the INTERVAL to an INTEGER... _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
nagarjun_vv |
Posted: Thu Aug 13, 2009 7:56 pm Post subject: |
|
|
Apprentice
Joined: 24 Jun 2008 Posts: 33
|
Did you check what value you are getting from that.
SET OutputRoot.XML.Hi = (TIMESTAMP '2009-08-13 15:44:00' - TIMESTAMP '1999-08-13 15:44:00') SECOND;
Check the value and do the required changes for that.
Regards,
Nagarjun. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Aug 13, 2009 8:49 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Don't mess with the XML Domain ulness by some mistake you are using this depreciated parser. If you want to work with XML then use the XMLNSC domain.
As kimbert indicated, you need to CAST the result of your timestamp subtraction to an Integer.
Please look up the CAST ESQL Statememnt in the Documentation. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
dean |
Posted: Mon Aug 17, 2009 4:30 am Post subject: solution |
|
|
Novice
Joined: 29 May 2009 Posts: 15
|
this worked for me:
DECLARE HrTmStmpSec INTEGER CAST ((datestamp - TIMESTAMP '1970-01-01 00:00:00') SECOND as INTEGER);
thanks to all.
:clap: |
|
Back to top |
|
 |
kimbert |
Posted: Mon Aug 17, 2009 4:38 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
smdavies99 said:
Quote: |
As kimbert indicated, you need to CAST the result of your timestamp subtraction to an Integer. |
Nope. mgk said that. He's right, though. |
|
Back to top |
|
 |
|