sqldb2timestampdiff

TIMESTAMPDIFF Missing Days


Can someone explain to me why this returns only 360 days and not 365 days?

I expect it to not count the first day but, what about the other 4 days?

SELECT
(TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2017-12-31') - TIMESTAMP('2017-01-01'))))
FROM sysibm.sysdummy1

I am planning on just adding + 5 at the end.


Solution

  • If you have DB2 for Linux, Unix and Windows - now called Db2 - Version 11.1 you could also use

    SELECT DAYS_between('2017-12-31','2017-01-01') FROM SYSIBM.SYSDUMMY1