Skip to content
Advertisement

Find nearest day of week for a given date and day of week

For a pair of dates (date1, date2) = (Fri 2021-01-01, Wed 2020-01-01) I need to extract the day of week from date1 (Friday in this case) then find the nearest Friday (or whatever) for date2.

The result for the above pair would be Fri 2020-01-03 (2 days after that Wednesday) and not Fri 2019-12-27 (5 days before that Wednesday).

There are examples that find previous/next day-of-week, use a hard-coded day of week or use SET DATEFIRST statement; all of which I must avoid. Here is some test data — pair of dates and expected result:

Advertisement

Answer

Assuming you can create/modify a calendar dimension, is this what you are after?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement