Between more than 30 days and less than 90 days

I need to return records where there is a date older than 30 days, but less than 90 days. therefore, if someone bought something either 31 days ago or 89 days ago, those are the lines that I need to return, ignoring the last 30 days and nothing beyond 90 days.

+4
source share
2 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) 

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

Demo

+4
source
 WHERE DATEDIFF(now(),date)>30 and DATEDIFF(now(),date)<90 
0
source

Source: https://habr.com/ru/post/1501613/


All Articles