Labels

Wednesday, June 14, 2017

T-SQL Trick: How to Find Monday (or Any Day) of the Current Week

Ever needed to filter a report so it only shows data starting from the beginning of the current week? In SQL Server, calculating the date for "this past Monday" is a classic challenge that every dev faces eventually.

While there are many ways to do it, the most efficient method uses a clever combination of DATEDIFF and DATEADD.

The Logic: How It Works

The secret sauce is calculating the number of weeks that have passed since "Day 0" (which is 1900-01-01, a Monday) and then adding those weeks back to that same starting point.

Here is the cleanest way to write it:

-- Using the 'WK' shorthand

SELECT DATEADD(WK, DATEDIFF(WK, 0, GETDATE()), 0) AS MondayOfCurrentWeek;

-- Or using the full 'WEEK' keyword for readability

SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0) AS MondayOfCurrentWeek;

Both queries will return the exact date of Monday for the current week (e.g., 2026-04-13).


Getting Other Days of the Week

The beauty of this snippet is its flexibility. If you need to find Tuesday, Wednesday, or any other day, you don't need to rewrite the logic—you just need to shift the "anchor" value (the 0 in the formula).

By incrementing the integer, you move the target day forward:

-- Tuesday

SELECT DATEADD(WK, DATEDIFF(WK, 0, GETDATE()), 1) AS Tuesday;

-- Wednesday

SELECT DATEADD(WK, DATEDIFF(WK, 0, GETDATE()), 2) AS Wednesday;

-- Thursday

SELECT DATEADD(WK, DATEDIFF(WK, 0, GETDATE()), 3) AS Thursday;


Why use this instead of DATEPART?

The main advantage here is that this method is deterministic and ignores your server's DATEFIRST settings. Whether your server thinks the week starts on Sunday or Monday, this math always anchors back to that original Monday in 1900, keeping your reports consistent across different environments.