Appearance
NEXT_DAY
Based on a specific date or timestamp, return the next date when a given day of the week falls.
NEXT_DAY ( { date | timestamp | timestamptz }, day )
Use the date
or timestamp
keyword if you want to specify a literal value for the date. For example:
date '2017-11-20'
timestamp '2017-11-20 12:15:01
The following example returns the date of the next Monday after the current date:
premdb=# select current_date, next_day(current_date,'Monday');
date | next_day
------------+------------
2017-11-20 | 2017-11-27
(1 row)
The following example returns the date of the first Thursday in the year 2000:
premdb=# select next_day(date '1999-12-31','Th') from sys.const;
next_day
------------
2000-01-06
(1 row)
If the day of the week you specify is the same as the day of the week in the given date, the function returns the next occurrence of that day.
Valid day
values include a number of abbreviations:
Sunday
,Su
,Sun
Monday
,M
,Mo
,Mon
Tuesday
,Tu
,Tues
Wednesday
,W
,We
,Wed
Thursday
,Th
,Thu
,Thurs
Friday
,F
,Fr
,Fri
Saturday
,S
,Sa
,Sat