Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Between older than 30 days and less than 90days

I need to return records where there is a date older than 30days but less than 90days. so If someone bought something either 31 days ago or 89 days ago its those rows i need to return, ignoring the last 30 days and anything outside of 90days.

like image 392
GPH Avatar asked Oct 03 '22 00:10

GPH


1 Answers

WHERE DateCol < DATEADD(dd, DATEDIFF(dd, 0, DATEADD(dd,-30, GetDate())), 0)
AND   DateCol > DATEADD(dd, DATEDIFF(dd, 0, DATEADD(dd,-90, GetDate())), 0)

The DATEADD-DATEDIFF truncates the time part, so that 30 days ago means midnight 30 days ago.

Demo

like image 158
Tim Schmelter Avatar answered Oct 07 '22 18:10

Tim Schmelter