Author |
Message
|
Bichu |
Posted: Fri Sep 16, 2016 8:38 am Post subject: Timestamp format |
|
|
Centurion
Joined: 16 Oct 2011 Posts: 124 Location: London
|
Hallo Guys,
I know you might read through similar kind of stuffs over here so many times because I have also read through but couldn't find a solution to my problem.
I am just trying to get the current time and i would like it to be in the format HH:mm:ss.
DECLARE castTime TIME;
SET castTime = CAST (CURRENT_GMTTIME AS TIME FORMAT 'HH:mm:ss');
But the output is always similar to HH:mm:ss.sss(eg: 17:07:20.149)
I have read through the below link in detail and implemented as such but still no luck
http://www.ibm.com/support/knowledgecenter/SSKM8N_8.0.0/com.ibm.etools.mft.doc/ak05616_.htm
Could you guys point out where am I going wrong.
I am working on IIB V9.0.0 |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 16, 2016 8:42 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Format only applies when casting to a date/time/datetime from a string or casting from a data/time/datetime to a string.
date/time/datetimes don't have any "format", they're a primitive type. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
Vitor |
Posted: Fri Sep 16, 2016 8:47 am Post subject: Re: Timestamp format |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Bichu wrote: |
Could you guys point out where am I going wrong. |
You're casting to a TIME datatype, which has the format you're seeing when implicitly cast to a character datatype.
If you're trying to output the timestamp as a character string with a format "HH:mm:ss" then you should probably do that.
If you're trying to do something else, you problem need to explain it further _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Sep 16, 2016 8:51 am Post subject: Re: Timestamp format |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Bichu wrote: |
I am working on IIB V9.0.0 |
Pedantically, you're not. IIB has 4 levels to it's version - 9.0.0.n
This is important because the last level is the fix pack level you're using. Calling it 9.0.0 doesn't say what maintenance you've got applied and renders us unable to determine if the problem is within the software (and there's a known fix), in your code or between your ears.
This specific problem appears to be the latter. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
rekarm01 |
Posted: Fri Sep 16, 2016 9:46 am Post subject: Re: Timestamp format |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
Bichu wrote: |
Code: |
SET castTime = CAST (CURRENT_GMTTIME AS TIME ...); |
|
There is also the CURRENT_TIME function, which doesn't need casting from GMTTIME to local TIME. |
|
Back to top |
|
 |
Bichu |
Posted: Mon Sep 19, 2016 1:00 am Post subject: Re: Timestamp format |
|
|
Centurion
Joined: 16 Oct 2011 Posts: 124 Location: London
|
Vitor wrote: |
If you're trying to output the timestamp as a character string with a format "HH:mm:ss" then you should probably do that. |
This is what I need vitor. But I need the current time. Hence I am getting the current time and trying to cast it to a string. |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Sep 19, 2016 1:14 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
In your original post we see this
Code: |
DECLARE castTime TIME;
SET castTime = CAST (CURRENT_GMTTIME AS TIME FORMAT 'HH:mm:ss');
|
Now you say that you want the Current time cast as a char.
A previous answer indicated that the CAST with format applies to a CHAR.
Combine the two and what do you get?
{hint, change the datatype of 'castTime'} _________________ 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 |
|
 |
Vitor |
Posted: Mon Sep 19, 2016 5:06 am Post subject: Re: Timestamp format |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Bichu wrote: |
trying to cast it to a string. |
No you're not.
Bichu wrote: |
Code: |
CAST (CURRENT_GMTTIME AS TIME |
|
If you read that in English (as you're clearly unable to read the description of the command in the InfoCenter) then it says:
"Cast the current GMT time as a time"
What part of that sounds like:
"Cast the current GMT time as a string"
How can you even think that would do what you want?
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Sep 19, 2016 5:26 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
No kind of date or time variable in IIB will have any format at all.
As said, Format is used to cast FROM a character to a date, or FROM a date to a character. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
Bichu |
Posted: Mon Sep 19, 2016 6:09 am Post subject: |
|
|
Centurion
Joined: 16 Oct 2011 Posts: 124 Location: London
|
Thanks all. I have got the output now.
DECLARE castTime CHARACTER;
SET castTime = CAST (CURRENT_TIME AS CHARACTER FORMAT 'HH:mm:ss'); |
|
Back to top |
|
 |
|