If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Date conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-09, 13:37
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
Date conversion

I have a column which gives date as Java long type - 1241436617660,1241436617145 etc. How do I convert this to

Required Result as -
Mon May 04 07:30:18 EDT 2009

select td from table_time;

Input
td - 1241436617660,1241436617145
Reply With Quote
  #2 (permalink)  
Old 05-04-09, 14:58
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I assume the value is in milliseconds based on you other post.

select timestamp('01/01/1970','00:00:00') + (Mycol * 1000) microseconds from ...


Andy
Reply With Quote
  #3 (permalink)  
Old 05-04-09, 15:15
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I thoght that you need to do conversions of these three steps.
1) Miliseconds to DB2 TIMESTAMP.
2) UTC to EDT(local time zone).
3) Format it as 'DAY MON DD HH24:MI:SS EDT YYYY'.

Andy answered for step 1).

For step 2), add CURRENT TIMEZONE to UTC.
Or, you may want to use NEW_TIME in Sample UDFs for Migration.

For step 3), you may want to use VARCHAR_FORMAT(a synonym is TO_CHAR) for DD, HH24, MI. SS and YYYY
on DB2 for LUW 9.5, DB2 for iSeries V6R1 or DB2 for z/OS V9.
You can use SUBSTR(DAYNAME(ts), 1, 3) for DAY and SUBSTR(MONTHNAME(ts), 1, 3) for MON.
Reply With Quote
  #4 (permalink)  
Old 05-04-09, 15:39
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
I'm using this, but time seems to invalid....

DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,

TIME(
TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds

Please advise.
Reply With Quote
  #5 (permalink)  
Old 05-04-09, 15:59
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Conversion from Timestamp to Decimal will return yyyymmddhhmmss.nnnnnn.

So, CAST(t.timestampis as DECIMAL(31,0))/1000 may return yyyymmddhhm.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On