|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Getting a timestamp to adhere to ISO 8601 format... |
« View previous topic :: View next topic » |
Author |
Message
|
Empeterson |
Posted: Thu Feb 26, 2004 10:58 am Post subject: Getting a timestamp to adhere to ISO 8601 format... |
|
|
Centurion
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
|
ISO 8601 standard basically says that a date/time stamp should be in the follwing format:
YYYY-MM-DDTHH:MM:SS
The key here is the 'T" located before the time. The function CURRENT_TIMESTAMP returns:
YYYY-MM-DD HH:MM:SS
without the 'T'. I have tried a few different ways to construct that timestamp with the 'T' in it, but every time I either get an error or it doesnt come out quite right. I am starting to get very frustrated. I am sure there is something I am missing. I will outline below all the things I have tried. Please let me know if I have over looked anything.
1) First, I tried this:
SET OutputRoot.XML.Root.Timestamp = CURRENT_DATE || 'T' || CURRENT_TIME;
This wouldnt even deploy. I get this error in the log:
BIP2420E: (34, 103) : Invalid or incompatible data types for '||' operator.
2) Ok, so then I try this:
DECLARE myDate CHARACTER
DECLARE myTime CHARACTER
SET myDate = CURRENT_DATE;
SET myTime = CURRENT_TIME;
SET OutputRoot.XML.Root.Timestamp = myDate || 'T' || myTime;
This gives me:
<Root>
<Timestamp>DATE '2004-02-26'TTIME '13:28:12.462622'</Timestamp>
<Root>
which adds all that extra funky stuff in there.
3) Next I tried to declare my variables as date and time types:
DECLARE myDate DATE;
DECLARE myTime TIME;
SET myDate = CURRENT_DATE;
SET myTime = CURRENT_TIME;
SET OutputRoot.XML.Root.Timestamp = myDate || 'T' || myTime;
This is basically the same as 1), but interstingly enough, this deploys. It throws an exception though, the description being 'wrong type exception'.
4) Ok, so now I try and explicitly do the cast:
DECLARE myDate DATE;
DECLARE myTime TIME;
SET myDate = CURRENT_DATE;
SET myTime = CURRENT_TIME;
SET OutputRoot.XML.Root.Timestamp = CAST(myDate AS CHARACTER) || 'T' || CAST(myTime AS CHARACTER);
Not surprisingly, this returns the same result as 2).
5) My last attempt was to use EXTRACT to extract all the pieces I needed and rebuild them into the ISO format. The problem with EXTRACT is that it returns an integer, so if you grab a timestamp where any of the values are from 1-9, then you get a single digit rather then the 2 digit format that is required, ie 01,02 etc. Lets say its 9:02am. You run the follwing:
SET myTime = EXTRACT(HOUR FROM CURRENT_TIME) || EXTRACT(MINUTE FROM CURRENT_TIME);
You will get 92, not 0902 which would be the correct way to display that time. I could do a check on that value and if it is less than 10, I could throw a zero in front of it I guess, but that seems like a lot of work just to produce a timestamp. Maybe I am overlooking something simple and making this way too complicated, but it seems to me that the date/time functions could use some work. If anyone could offer any suggestions I would appreciate it. Thank you.
FYI: I am running WMQI 2.1, CSD4. _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Feb 26, 2004 11:30 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
There is sample code buried in the archives here for this forum that will give you the right code to use for combining the results of Extract so that you can get an ISO time stamp with padded decimals. It basically involves adding 100 to two digit numbers, and then taking the last two characters of the string conversion.
Try searching for Extract and see if that gets you to it quickly. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
EddieA |
Posted: Thu Feb 26, 2004 11:45 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Start with your (2).
SET OutputRoot.XML.Root.Timestamp = SUBSTRING(myDate FROM 6 FOR 10) || 'T' || SUBSTRING(myTime FROM 6 FOR 8);
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
Sandman |
Posted: Thu Feb 26, 2004 11:55 am Post subject: |
|
|
Centurion
Joined: 16 Oct 2001 Posts: 134 Location: Lincoln, RI
|
This works too:
Code: |
DECLARE ts1 CHAR;
SET Environment.Variables.TS = CAST(CURRENT_TIMESTAMP AS CHAR); -- Format: TIMESTAMP '2004-02-26 14:48:07.330'
SET Environment.Variables.TS_ISO =
SUBSTRING(Environment.Variables.TS FROM 12 FOR 10)
|| 'T'
|| SUBSTRING(Environment.Variables.TS FROM 23 FOR 12); |
And results with:
Code: |
* Environment
(
(0x1000000)Variables = (
(0x3000000)TS = 'TIMESTAMP '2004-02-26 14:51:07.556''
(0x3000000)TS_ISO = '2004-02-26T14:51:07.556'
)
) |
|
|
Back to top |
|
 |
Empeterson |
Posted: Thu Feb 26, 2004 12:15 pm Post subject: |
|
|
Centurion
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
|
Thank you everyone for your suggestions. I should have thought of some of those myself.  _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|