Spark SQL - Get Next Monday, Tuesday, Wednesday, Thursday, etc.

visibility 13 access_time 12 days ago languageEnglish timeline Stats
timeline Stats
Page index 1.00
more_horiz
Spark SQL - Get Next Monday, Tuesday, Wednesday, Thursday, etc.

Spark SQL provide a very convenient function named next_day since version 1.5.0. It can be used to calculate the next date that is after a certain date with specified name.

Syntax

next_day(start_date, day_of_week)

The function returns the first date which is later than start_date and named as indicated by day_of_week.

Code snippet

The following examples calculate any day of the week after.

spark-sql> select next_day(DATE'2022-06-16', 'Monday');
2022-06-20
spark-sql> select next_day(DATE'2022-06-16', 'TU');
2022-06-21
spark-sql> select next_day(DATE'2022-06-16', 'WE');
2022-06-22
spark-sql> select next_day(DATE'2022-06-16', 'TH');
2022-06-23
spark-sql> select next_day(DATE'2022-06-16', 'FR');
2022-06-17
spark-sql> select next_day(DATE'2022-06-16', 'FRIDAY');
2022-06-17
spark-sql> select next_day(DATE'2022-06-16', 'Sat');
2022-06-18
spark-sql> select next_day(DATE'2022-06-16', 'Sun');
2022-06-19

The function returns the right date per calendar:


copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
Spark SQL - Get Current Timezone
visibility 25
thumb_up 0
access_time 12 days ago
Spark SQL - element_at Function
visibility 30
thumb_up 0
access_time 24 days ago
[Diagram] Spark SQL Joins - Left Anti Join image
visibility 18
thumb_up 0
access_time 28 days ago
Spark SQL Joins - Left Anti Join