Joined: 23 Sep 2003 Posts: 232 Location: IBM (Retired)
If you are running WMB V6 then you now have the ability to use the FORAMT pattern option on a cast. Thus, it becomes much easier to extract time information or dates, etc and cast them as charbstring.acters - without using the substring. In addition, there are several new wasy of managing dates. Let me give you an example: Here we have a date value given with a mixture of alpha values and numerics - this is an actual date that came from a web service - the objective of this code was to change the value into all numerics ans as a character string. While one could combine some steps together - individual steps are shown for clarity.
-- WSDate was taken from a soap trace
Declare WSDate CHAR 'Wed Feb 22 13:32:14 PST 2006';
set Environment.WSDate = WSDate;
set Environment.pattern = pattern;
Set MyTimeStamp = Cast(WSDate as TIMESTAMP FORMAT pattern);
set Environment.MyTimeStamp = MyTimeStamp;
Declare DB2Date CHAR
CAST(EXTRACT(YEAR FROM MyTimeStamp) AS CHAR FORMAT '0000') || '-' ||
CAST(EXTRACT(MONTH FROM MyTimeStamp) AS CHAR FORMAT '00') || '-' ||
CAST(EXTRACT(DAY FROM MyTimeStamp) AS CHAR FORMAT '00') || '-' ||
CAST(EXTRACT(HOUR FROM MyTimeStamp) AS CHAR FORMAT '00') || '.' ||
CAST(EXTRACT(MINUTE FROM MyTimeStamp) AS CHAR FORMAT '00') || '.' ||
CAST(EXTRACT(SECOND FROM MyTimeStamp) AS CHAR FORMAT '00') || '.' ||
'000000';
set Environment.DB2Date = DB2Date;
/* the Environment values are:
WSDate = 'Wed Feb 22 13:32:14 PST 2006'
pattern = 'EEE MMM dd HH:mm:ss zzz yyyy'
MyTimeStamp = TIMESTAMP '2006-02-23 03:32:14'
DB2Date = '2006-02-23-03.32.14.000000'
mytime = 'TIMESTAMP '2006-02-23 03:32:14''
myftime = '2006-02-23 03:32:14'
*/ _________________ Bill Matthews
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