How to print last sunday of the year in oracle?

by scotty_walker , in category: MySQL , 10 months ago

How to print last sunday of the year in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 10 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.

Related Threads:

How to extract the year from a date in oracle?
How to insert 0001 year in oracle?
How to separate range of year on oracle?
How to use month and year in to_char in oracle?
How to get year and month into number oracle?
How to find the last access time of a schema in oracle?