DATE function to get past 60 days of data

marketing-cloudquerysql

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.

Best Answer

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).

Related Topic