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 > Unix timestamp to DB2 date and time conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-05, 08:07
milacek milacek is offline
Registered User
 
Join Date: Nov 2005
Location: Prague, Czech Republic
Posts: 8
Unix timestamp to DB2 date and time conversion

Hi all,

I have the following problem:

In the column I have integer values with Unix timestamp, and need to write a trigger which will fill TIME and DATE column with the appropriate data.

Can someone help me how to build the trigger ?

Thanks to all
Reply With Quote
  #2 (permalink)  
Old 11-11-05, 10:09
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Looks like you're going to have to write a Java or C function, doesn't seem to be a built-in function to convert the epoch to DATE/TIME.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 11-11-05, 10:43
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
How about this:
Code:
$ db2 "values (timestamp('1970-01-01','00.00.00') + int(1131722349/86400) days + int(mod(1131722349,86400)) seconds)"

1
--------------------------
2005-11-11-15.19.09.000000

  1 record(s) selected.
It gives you a UTC timestamp; you may need to adjust for the local time zone.
Reply With Quote
  #4 (permalink)  
Old 11-11-05, 11:02
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Nice solution.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #5 (permalink)  
Old 11-23-05, 06:05
milacek milacek is offline
Registered User
 
Join Date: Nov 2005
Location: Prague, Czech Republic
Posts: 8
Nice

Nice - thank you in advance ....
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