以下TIMESTAMPDIFF
功能仅限每月30天。
当月份少于或超过30天时如何使用TIMESTAMPDIFF
功能?
OTHER_VOUCHER_DATE
(1/1/2012)的开始日期
SELECT
SUPPLIER_CODE,
TRN_CURRENT_BAL_HOME AS AMT_DUE,
OTHER_VOUCHER_DATE,
SUM(CASE WHEN TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) <=30 THEN TRN_CURRENT_BAL_HOME END) AS 0-30 DAYS,
SUM(CASE WHEN TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) >=31 AND TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) <=60 THEN TRN_CURRENT_BAL_HOME END) AS 31-60 DAYS,
SUM(CASE WHEN TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) >=61 AND TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) <=90 THEN TRN_CURRENT_BAL_HOME END) AS 61-90 DAYS,
SUM(CASE WHEN TIMESTAMPDIFF(16,CHAR(TIMESTAMP('2015-02-01-00.00.00.000000')-TIMESTAMP( OTHER_VOUCHER_DATE))) >90 THEN TRN_CURRENT_BAL_HOME END) AS MORE THAN 90 DAYS
FROM AP_AGING
有什么想法吗?
谢谢。
答案 0 :(得分:0)
HSQLDB计算每月正确的天数。您的示例未使用正确的语法,并将引发异常。
下面给出了如何使用TIMESTAMPDIFF的示例。请注意在时间戳字符串中正确使用分隔符:
CALL TIMESTAMPDIFF(SQL_TSI_DAY, TIMESTAMP('2015-03-01 00:00:00.000000'), TIMESTAMP('2015-02-01 00:00:00.000000'))
该示例返回28,即2月的第一天和3月的第一天之间的天数。