Logo Questions Linux Laravel Mysql Ubuntu Git Menu

SQL server: How do i get the date of previous Saturday

I need to filter a table from last Saturday 7pm to now. How do i do that?

The column i'm filtering is of dateTime2(0) format?

like image 539
Fearghal Avatar asked Mar 22 '23 02:03


2 Answers

This expression will always give you the previous Saturday at 7pm, independent of your DATEFIRST setting:

select DATEADD(week,

If it's run on a Saturday, it'll give you the previous Saturday.

like image 145
Damien_The_Unbeliever Avatar answered Apr 06 '23 04:04


SELECT * From TableName Where MyDate >= DATEADD(HH,19, DATEADD(DAY, (DATEDIFF(DAY, '19000106', GetDate()) - 1) / 7 * 7, '19000106'))

like image 32
Fred Avatar answered Apr 06 '23 03:04