next_day function

Returns the first date which is later than expr and named as in dayOfWeek.

Syntax

next_day(expr, dayOfWeek)

Arguments

  • expr: A DATE expression.

  • dayOfWeek: A STRING expression identifying a day of the week.

Returns

A DATE.

dayOfWeek must be one of the following (case insensitive):

  • 'SU', 'SUN', 'SUNDAY'

  • 'MO', 'MON', 'MONDAY'

  • 'TU', 'TUE', 'TUESDAY'

  • 'WE', 'WED', 'WEDNESDAY'

  • 'TH', 'THU', 'THURSDAY'

  • 'FR', 'FRI', 'FRIDAY'

  • 'SA', 'SAT', 'SATURDAY'

Note

If spark.sql.ansi.enabled is false the function returns NULL instead of an error for a malformed dayOfWeek.

Examples

> SELECT next_day('2015-01-14', 'TU');
 2015-01-20