namsaray
namsaray

Reputation: 51

Convert seconds since 1980 in DB2

I'm looking for a way to convert seconds since 1980 to DB2 TIMESTAMP using SQL, DB2 functions, column data type - whatever works. Is that possible?

Thank you

Upvotes: 0

Views: 1806

Answers (2)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

Try this:

SELECT TIMESTAMP ('1980-01-01-00.00.00.000000') + X SECOND
    FROM SYSIBM.SYSDUMMY1; 


SELECT TIMESTAMP ('1980-01-01-00.00.00.000000') + 6000000 SECOND 
    FROM SYSIBM.SYSDUMMY1;
1980-03-10 10:40:00

Upvotes: 2

dan1111
dan1111

Reputation: 6566

How much precision do you need? This should convert your value to a date (assuming that your date format is in sec_value):

date(sec_value / 86400 + days('1980-01-01'))

If you need precision beyond that, it wouldn't be so hard to roll your own math to get the hours and seconds. A quick search didn't turn up any built-in functionality that does this.

Upvotes: 0

Related Questions