Author |
Message
|
Skumarmly |
Posted: Mon Jun 15, 2015 5:35 am Post subject: timestamp formatting |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
In response I could see date field with value Mon, 15 Jun 2015 13:32:17 GMT(character) I need that in Timestamp format yyyy-mm-dd hh:mm:ss
I used cast function but its throwing error
suggest me the code its v urgent |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Jun 15, 2015 5:44 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
What is the code that you are using for the cast? _________________ 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 |
|
 |
mqjeff |
Posted: Mon Jun 15, 2015 5:49 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You don't need it in any format until you put it in an output field that does not contain a date or time or datetime type.
What happens if you simply don't try to cast it? |
|
Back to top |
|
 |
Skumarmly |
Posted: Mon Jun 15, 2015 7:26 am Post subject: |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
DECLARE respTime CHARACTER InputRoot.HTTPResponseHeader.Date;
DECLARE RespTime TIMESTAMP CAST(respTime AS TIMESTAMP FORMAT 'EEE,DD-MMM-YYYY HH:MM:SS'); |
|
Back to top |
|
 |
Skumarmly |
Posted: Mon Jun 15, 2015 7:30 am Post subject: |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
I'm planning to add some Minutes to that time stamp to perform transactions till that time ends.
once the current time Reaches that time transactions should stop or again request for a new expiry time |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 15, 2015 7:31 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can't cast a timestamp to a timestamp.
You can't specify that a timestamp has a specific format. It's a timestamp.
If you want to add minutes, you simply add minutes. |
|
Back to top |
|
 |
Skumarmly |
Posted: Mon Jun 15, 2015 7:36 am Post subject: |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
under InputRoot.HTTPResponseHeader.Date I have " Mon, 15 Jun 2015 13:32:17 GMT "
so you mean to say I cant cast this character to timestamp??? |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 15, 2015 7:44 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can cast a character to a timestamp.
The format in this case is the format of the data in the character.
So you use the format to tell the case how to understand the string.
Once it's a timestamp, you don't need to cast it again until you're done with it. Then the format tells the cast how to output the timestamp. |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Jun 15, 2015 7:44 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
If you put a Trace node before your Compute Node and set the output pattern to
${Root}
You will see that the InputRoot.HTTPResponseHeader.Date is shown as Mon, 15 Jun 2015 13:32:17 GMT
but the data type is TIMESTAMP. You can't cast a TIMESTAMP to a TIMESTAMP.
You can cast the TIMESTAMP to a CHAR that will give you the formatted output you desire with proper use of the FORMAT paramter of the CAST statement. _________________ 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 |
|
 |
Skumarmly |
Posted: Mon Jun 15, 2015 10:05 am Post subject: |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
DECLARE respTime CHARACTER CAST(InputRoot.HTTPResponseHeader.Date AS CHARACTER FORMAT 'yyyy-MM-dd HH:mm:ss');
but its not formatting
respTime:CHARACTER:Mon, 15 Jun 2015 18:04:04 GMT
am getting as it is |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jun 15, 2015 10:26 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Skumarmly wrote: |
DECLARE respTime CHARACTER CAST(InputRoot.HTTPResponseHeader.Date AS CHARACTER FORMAT 'yyyy-MM-dd HH:mm:ss');
but its not formatting
respTime:CHARACTER:Mon, 15 Jun 2015 18:04:04 GMT
am getting as it is |
Could that be because even though InputRoot.HTTPResponseHeader.Date CONTAINS a date information, the TYPE of the field seems to be CHARACTER....  _________________ MQ & Broker admin |
|
Back to top |
|
 |
wbisantosh |
Posted: Mon Jun 15, 2015 10:38 am Post subject: |
|
|
Apprentice
Joined: 12 Nov 2012 Posts: 47
|
Try this,
Code: |
DECLARE outTS CHAR;
DECLARE inTS TIMESTAMP;
SET inTS = CAST(InputRoot.HTTPResponseHeader.Date AS TIMESTAMP FORMAT 'EEE, dd MMM YYYY HH:mm:ss zz');
SET outTS = CAST(inTS AS CHARACTER FORMAT 'yyyy-MM-dd HH:mm:ss'); |
The Input is the TIMESTAMP and Output will be CHAR
Santosh |
|
Back to top |
|
 |
Skumarmly |
Posted: Mon Jun 15, 2015 11:36 pm Post subject: |
|
|
Novice
Joined: 09 Sep 2014 Posts: 13
|
Thanks Santosh ,this code served my purpose and thanks everyone  |
|
Back to top |
|
 |
|