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 > How to convert Milliseconds to Date in DB2?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-06, 12:52
vinodtr vinodtr is offline
Registered User
 
Join Date: Dec 2006
Posts: 8
How to convert Milliseconds to Date in DB2?

Hi all,

I have a date which is represented by the number of milliseconds since January 01, 1970. I need to change this back to DATE format. Is there any built in function in DB2 to do the needed conversion ?

In Oracle i was able to do the conversion by the following statement.

select to_char(to_date('01/01/1970','mm/dd/yyyy'),'mm/dd/yyyy') + milliseconds/86400000) from dual;

Note: In the above sql statement, milliseconds is the no: of milliseconds of the desired date.
Reply With Quote
  #2 (permalink)  
Old 12-20-06, 13:01
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You should be able to do it with straight math:


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

Andy
Reply With Quote
  #3 (permalink)  
Old 12-20-06, 15:36
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Make sure that you account for the timezone difference - UNIX time (milliseconds since 1/1/1970) is always UTC.
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