v.23.5New Feature

Added toLastDayOfWeek Function for Rounding Dates to Nearest Weekend

Added toLastDayOfWeek function to round a date or a date with time up to the nearest Saturday or Sunday. #50315 (Victor Krasnov).
Added the toLastDayOfWeek function to round a date or datetime value up to the nearest Saturday or Sunday.

Why it matters

This feature helps users to easily find the end of the week for any given date or datetime by rounding up to the closest Saturday or Sunday. It simplifies calculations related to week-ending dates, which is useful in reporting, analytics, and scheduling scenarios where week boundaries need to be identified.

How to use it

Use the toLastDayOfWeek function in your queries by passing a Date or DateTime value as the argument. The function will return the date rounded up to the nearest Saturday or Sunday. For example:

SELECT toLastDayOfWeek('2024-06-20') AS last_day_of_week


will return the date of the closest Saturday or Sunday on or after the given date.