DB2本身的内置函数,缺点是是近似值,用法如下:
SELECT
timestampdiff (256, char(timestamp('2017-05-27 23:00:00') - timestamp('2017-05-25 10:40:00'))) AS "间隔年",
timestampdiff (128, char(timestamp('') - timestamp(''))) AS "间隔季度",
timestampdiff (64, char(timestamp('') - timestamp(''))) AS "间隔月",
timestampdiff (32, char(timestamp('') - timestamp(''))) AS "间隔周",
timestampdiff (16, char(timestamp('') - timestamp(''))) AS "间隔日",
timestampdiff (8, char(timestamp('') - timestamp(''))) AS "间隔时",
timestampdiff (4, char(timestamp('') - timestamp(''))) AS "间隔分",
timestampdiff (2, char(timestamp('') - timestamp(''))) AS "间隔秒"
FROM SYSIBM.SYSDUMMY1;
相见时难别亦难