SNIPPET
2 Upvotes

Getting the Date for the Previous Saturday with T-SQL

SQL
Querying

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)

By GregHe1979 - Last Updated Dec. 1, 2020, 3:07 p.m.

COMMENTS
RELATED SNIPPETS
Search Snippets by Tag: