SELECT ROUND (SYSDATE, 'YEAR') "As of day" FROM DUAL
/
1/1/2022
SELECT ROUND (TO_DATE ('12-mar-2021'), 'YEAR') "Current Year" FROM DUAL
/
1/1/2021
SELECT ROUND (TO_DATE ('12-aug-2021'), 'YEAR') "New Year" FROM DUAL
1/1/2022
First and Last Day of the year
SELECT TRUNC (SYSDATE, 'YEAR') "First Day" FROM DUAL;
/
1/1/2021
SELECT ADD_MONTHS (TRUNC (SYSDATE, 'YEAR'), 12) - 1 "Last Day" FROM DUAL;
/
12/31/2021
First and last Day of Month
SELECT TRUNC (SYSDATE) - (TO_NUMBER (TO_CHAR (SYSDATE, 'DD')) - 1) FIRST_DAY FROM DUAL;
/
10/1/2021
SELECT ADD_MONTHS ( TRUNC (SYSDATE) - (TO_NUMBER (TO_CHAR (SYSDATE, 'DD')) - 1), 1) - 1 LAST_DAY FROM DUAL;
/
10/31/2021
SELECT ADD_MONTHS ( TRUNC (SYSDATE) - (TO_NUMBER (TO_CHAR (SYSDATE, 'DD')) - 1), 1) - 1 LAST_DAY,
TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1)))+1, TRUNC(LAST_DAY(SYSDATE)) ,
TRUNC(LAST_DAY(SYSDATE)) LAST_D
FROM DUAL;
10/31/2021 10/1/2021 10/31/2021 10/31/2021
No comments:
Post a Comment