在DB2数据库中计算天数问题?超过30天的计算问题?
在DB2数据库中计算天数问题,比如说date('2013-06-20-15.18.34')-date('2013-05-21-15.18.34')等于30,而date('...
在DB2数据库中计算天数问题,比如说date('2013-06-20-15.18.34')-date('2013-05-21-15.18.34')等于30,而date('2013-06-20-15.18.34')-date('2013-05-20-15.18.34')却等于100,再有date('2013-06-20-15.18.34')-date('2013-05-19-15.18.34')等于101。我自己试了下间隔等于30天或小于30天的计算出来的天数是正确的,而大于30天时便是错的。本人能力有限,还请各位高手多多指教。谢谢。
展开
1个回答
2013-06-20
展开全部
timestampdiff (, char(
timestamp('2011-10-06-00.00.00')-
timestamp( n, '2011-10-01-00.00.00')))
对于 n,可以使用以下各值来替代,以指出结果的时间单位:
1 = 秒的小数部分
2 = 秒
4 = 分
8 = 时
16 = 天
32 = 周
64 = 月
128 = 季度
256 = 年
SELECT
timestampdiff (256, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔年",
timestampdiff (128, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔季度",
timestampdiff (64, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔月",
timestampdiff (32, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔周",
timestampdiff (16, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔日",
timestampdiff (8, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔时",
timestampdiff (4, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔分",
timestampdiff (2, char(timestamp('2013-12-30 20:30:30') - timestamp('2001-09-26 15:24:23'))) AS "间隔秒"
FROM SYSIBM.SYSDUMMY1;
间隔年 间隔季度 间隔月 间隔周 间隔日 间隔时 间隔分 间隔秒
----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
12 49 147 637 4474 107381 6442866 386571967
1 条记录已选择。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |