5

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.

GPH
  • 1,817
  • 3
  • 29
  • 50
  • Take a look here http://stackoverflow.com/questions/5939954/sql-server-between-two-datetime-fields-not-working-correctly. It is possibly that you want. – Christos Sep 11 '13 at 08:38

2 Answers2

4
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

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0
WHERE DATEDIFF(now(),date)>30 and DATEDIFF(now(),date)<90
david
  • 3,225
  • 9
  • 30
  • 43