Oracle SQL Examples: Find Next or Previous Date

 

Overview

* Use next_day function: next_day(date, day_string)
* day_string is one of the following:

SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY

Find Next Sunday from Today

SELECT next_day(SYSDATE,'SUNDAY') FROM dual;

Find Next Sunday from a Specific Date

SELECT next_day(to_date('05-MAR-16'),'SUNDAY') FROM dual;
-- or
SELECT next_day('05-MAR-16','SUNDAY') FROM dual;

Find Next Monday from Today

SELECT next_day(SYSDATE,'MONDAY') FROM dual;

Frind Previous Sunday from Today

SELECT next_day(SYSDATE-7,'SUNDAY') FROM dual;

Frind Previous Sunday from a Specific Date

SELECT next_day(to_date('05-MAR-16')-7,'SUNDAY') FROM dual;
This entry was posted in oracle and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.