0

I am running a query to get data from the past 60 days and BEYOND. So basically I am trying to capture anyone whose installdate is Today - 60 days and beyond. And I should be getting data whose installdate is 6/12/2021 and beyond. But the query is returning data with the Month of July also. While I am expecting all data on and before 6/12/2021.

I tried the following values in WHERE CLAUSE, but none of them works... Any suggestion, please?

  1. InstallDate >= convert(date, getDate()-60)
  2. InstallDate >= DATEADD(day,-60, GETDATE())

Thanks.

2
  • 1
    I am confused on exactly what you are asking for. With dates, greater than means more recent. So you may have your operators backwards. If you want any records 60 days or more prior to today, you will need to do Convert(date, InstallDate) <= Convert(date, getDate() - 60) and then do >= for when you want 60 days or less prior to today(e.g. the last 60 days worth of data). Aug 11, 2021 at 21:19
  • Ohh yes... That was the stupid mistake I was doing :)... Thanks @Gortonington
    – Sohail
    Aug 11, 2021 at 21:27

1 Answer 1

1

Moving from comment to answer for easier reference:

With dates, greater than means more recent. So you may have your operators backwards.

If you want any records 60 days or more prior to today, you will need to do Convert(date, InstallDate) <= Convert(date, getDate() - 60)

and then do >= for when you want 60 days or less prior to today(e.g. the last 60 days worth of data).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.