ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Getting a timestamp to adhere to ISO 8601 format...

Post new topic  Reply to topic
 Getting a timestamp to adhere to ISO 8601 format... « View previous topic :: View next topic » 
Author Message
Empeterson
PostPosted: Thu Feb 26, 2004 10:58 am    Post subject: Getting a timestamp to adhere to ISO 8601 format... Reply with quote

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 &apos;2004-02-26&apos;TTIME &apos;13:28:12.462622&apos;</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
View user's profile Send private message Send e-mail AIM Address
jefflowrey
PostPosted: Thu Feb 26, 2004 11:30 am    Post subject: Reply with quote

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
View user's profile Send private message
EddieA
PostPosted: Thu Feb 26, 2004 11:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Sandman
PostPosted: Thu Feb 26, 2004 11:55 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Empeterson
PostPosted: Thu Feb 26, 2004 12:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Getting a timestamp to adhere to ISO 8601 format...
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.