NEXT_DAY Function
The NEXT_DAY function returns the earliest date that is later than its DATE or DATETIME first argument, and that falls on the day of the week that its second argument specifies. This second argument is a quoted string of three ASCII characters that abbreviates the English name of the day of the week.
- a DATE or DATETIME expression that evaluates to a date earlier than the return value.
- a character string of at least three ASCII characters that correspond to upper case letters in the range from ASCII 65 through ASCII 90. These three letters encode the abbreviation English name for a day of the week.
- The date is later than the date specified by the first argument.
- The date falls on the day of the week specified by the second argument.
Day of Week | Abbreviation | Day of Week | Abbreviation | |
---|---|---|---|---|
Sunday | 'SUN' |
Wednesday | 'WED' |
|
Monday | 'MON' |
Thursday | 'THU' |
|
Tuesday | 'TUE' |
Friday | 'FRI' |
|
Saturday | 'SAT' |
Any characters that follow the 3rd character of these
abbreviation strings are ignored. For example, both 'MONDAY'
and 'MONTAG'
are
valid specification for the 2nd argument, each specifying the next
Monday after the date in the first argument. HCL
OneDB™ issues
an error, however, if the second argument is a string such as 'MODNAY'
whose
first three characters do not match one of the weekday abbreviations
in the table above.
SELECT ship_date, NEXT_DAY(ship_date, 'SAT') AS next_saturday, NEXT_DAY(ship_date, 'SAT') - ship_date AS num_days FROM orders;
ship_date next_saturday num_days 06/01/2006 06/03/2006 2 02/12/2007 02/17/2007 5 05/31/2007 06/02/2007 2 05/23/2007 05/26/2007 3
The value returned by NEXT_DAY has the same data type as the first argument. If this argument is a DATE type, NEXT_DAY returns a DATE value. If the first argument is a DATETIME type, NEXT_DAY returns a DATETIME YEAR TO FRACTION(5) value.
Because ship_date in the preceding example is a DATE column, the returned dates are formatted as DATE values, rather than in DATETIME format.
sprintf(query, “,
“select next_day(?::date, 'SUN') from mytab”);
EXEC SQL prepare selectq from :query;
EXEC SQL declare select_cursor cursor for selectq;
EXEC SQL open select_cursor using :hostvar_date_input;
EXEC SQL fetch select_cursor into :var_date_output;