DB2时间SQL
当前日期:
SELECT TO_CHAR(CURRENT TIMESTAMP,'yyyy-MM-dd HH24:mi:ss') FROM SYSIBM.DUAL
SELECT TO_CHAR(SYSDATE,'yyyy-MM-dd HH24:mi:ss') FROM SYSIBM.DUAL
本周今日星期几:
-- 1为星期日
SELECT DAYOFWEEK(CURRENT DATE) FROM SYSIBM.DUAL
-- 1为星期一
SELECT DAYOFWEEK_ISO(CURRENT DATE) FROM SYSIBM.DUAL
本周第一天:
SELECT TO_CHAR(CURRENT DATE-(DAYOFWEEK_ISO(CURRENT DATE)-1),'yyyy-MM-dd') FROM SYSIBM.DUAL
本月第一天:
SELECT FIRST_DAY(CURRENT DATE) FROM SYSIBM.DUAL
SELECT TRUNCATE(CURRENT DATE,'MM') FROM SYSIBM.DUAL
本月最后一天:
SELECT LAST_DAY(CURRENT DATE) FROM SYSIBM.DUAL
上个月第一天:
SELECT FIRST_DAY(CURRENT DATE-1 MONTH) FROM SYSIBM.DUAL
SELECT TRUNCATE(CURRENT DATE-1 MONTH,'MM') FROM SYSIBM.DUAL
本年第一天:
SELECT TRUNCATE(CURRENT DATE,'yy') FROM SYSIBM.DUAL
去年第一天:
SELECT TRUNCATE(CURRENT DATE-1 YEAR,'yy') FROM SYSIBM.DUAL
去年今日:
SELECT TO_CHAR(SYSDATE-1 YEAR,'yyyy-MM-dd HH24:mi:ss') FROM SYSIBM.DUAL
一年中第几天:
SELECT DAYOFYEAR(CURRENT TIMESTAMP) FROM SYSIBM.DUAL
一年中第几周:
-- 周日是一周的第一天
SELECT WEEK(CURRENT TIMESTAMP) FROM SYSIBM.DUAL
-- 周一是一周的第一天
SELECT WEEK_ISO(CURRENT TIMESTAMP) FROM SYSIBM.DUAL
一年中第几月:
SELECT MONTH(CURRENT TIMESTAMP) FROM SYSIBM.DUAL