3.DB2 时间函数
1.获取当前时间
(1) CURRENT DATE
获取当前的日期
1 | SELECT CURRENT DATE AS "CURRENT_DATE" FROM AP_INFO; |
(2) CURRENT TIME
获取当前的时间
1 | SELECT CURRENT TIME AS "CURRENT_TIME" FROM AP_INFO; |
(3) CURRENT TIMESTAMP
获取当前的时间戳
1 | SELECT CURRENT TIMESTAMP AS "CURRENT_TIMESTAMP" FROM AP_INFO; |
2.获取时间信息
获取年份
1 | SELECT YEAR(CHANGE_TIME) AS "CHANGE YEAR" FROM AP_INFO; |
获取月份
1 | SELECT MONTH(CHANGE_TIME) AS "CHANGE MONTH" FROM AP_INFO; |
获取日
1 | SELECT DAY(CHANGE_TIME) AS "CHANGE DAY" FROM AP_INFO; |
获取小时(24H)
1 | SELECT HOUR(CHANGE_TIME) AS "CHANGE HOUR" FROM AP_INFO; |
获取分钟
1 | SELECT MINUTE(CHANGE_TIME) AS "CHANGE MINUTE" FROM AP_INFO; |
获取秒
1 | SELECT SECOND(CHANGE_TIME) AS "CHANGE SECOND" FROM AP_INFO; |
3.计算两个日期相差多少天
DAYS([DATE])
: 返回日期从 0001-01-01 以来的天数
1 | SELECT (DAYS(CURRENT DATE) - DAYS(CHANGE_TIME)) AS "BETWEEN DAYS" FROM AP_INFO; |