时间:2021-07-01 10:21:17 帮助过:4人阅读
实现当前时间,周,月,季度,半年,年的转换,其中特别注意的是周的处理,IW方式处理逻辑,如果本周有大于等于4天,本周属于几年,如果小于4天,本周属于下一年
以1990/12/31为例,这天属于199101周
SELECT TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYYMMDD‘)) AS PERIOD,
SYSDATE AS P_DATE,
TO_NUMBER(TO_CHAR(SYSDATE, ‘IYYYIW‘)) AS P_WEEK,
TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYY‘) || TO_CHAR(SYSDATE, ‘MM‘)) AS P_MONTH,
TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYY‘) || TO_CHAR(SYSDATE, ‘Q‘)) AS P_QUARTER,
CASE
WHEN TO_CHAR(SYSDATE, ‘MM‘) >= 7 THEN
TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYY‘) || ‘2‘)
ELSE
TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYY‘) || ‘1‘)
END AS P_HALF_YEAR,
TO_NUMBER(TO_CHAR(SYSDATE, ‘YYYY‘)) AS P_YEAR,
SYSDATE LAST_MODIFY_DATE
FROM DUAL T
Oracle日期转换为周,月,季度,半年,年
标签: