Search code examples
db2

Add day interval in DB2


I am using DB2 version 12.1 and in a DB2 table AAA, I have a column 'Date' (Integer - column size 10) values as shown below,

enter image description here

Now my intention is to make a select query in the same table to display in Date format as shown below,

enter image description here

In Sql server, it works fine with the below query for example,

(DATEADD(day, AAA.DATE, '1849-12-31 01:01:01.1111111'))

But in DB2 , it not worked as expected, I tried with different functions DAYS,ADD_DAYS as shown below,

SELECT DAYS('1849-12-31') + 59169 AS TEST FROM AAA WHERE condition;

SELECT ADD_DAYS('1849-12-31', 59169) AS TEST FROM AAA WHERE condition;

How can I make it on DB2?


Solution

  • The solution is differnt but simple and straight forward:

     select date('1849-12-31') + 58074 days from sysibm.sysdummy1