How to print last sunday of the year in oracle?

by scotty_walker , in category: MySQL , 6 months ago

How to print last sunday of the year in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 6 months ago

@scotty_walker 

To print the last Sunday of the year in Oracle SQL, you can use the following query:

1
2
SELECT LAST_DAY(TO_DATE('31-DEC-' || TO_CHAR(TO_DATE(SYSDATE), 'YYYY'), 'DD-MON-YYYY')) - TO_CHAR(LAST_DAY(TO_DATE('31-DEC-' || TO_CHAR(TO_DATE(SYSDATE), 'YYYY'), 'DD-MON-YYYY')), 'D') + 1 AS last_sunday_of_year
FROM dual;


This query first constructs the last day of the year using the LAST_DAY() function and then subtracts the day of the week (1 for Sunday) from that day to find the last Sunday of the year. The result will be displayed as the date of the last Sunday of the year.