Getting the Date for the Previous Saturday with T-SQL

SQL

Example of how to get the date for the previous Saturday for the current date using T-SQL.

/*SYNTAX*/
DATEADD(DAY, DATEDIFF(DAY, 5, GETDATE()) / 7 * 7, 5)

/*EXAMPLE*/

SELECT 
	ORDER_NO,
	PRODUCT_ID
FROM
	ORDERS
WHERE
	ORDER_DATE = DATEADD(DAY, DATEDIFF(DAY, 5, GETDATE()) / 7 * 7, 5)
Did you find this snippet useful?

Sign up for free to to add this to your code library

median
SQL

4
SQL RANK
SQL

4
EXISTS
SQL

3