实现当前时间,周,月,季度,半年,年的转换,其中特别注意的是周的处理,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
时间: 2024-11-03 21:14:35