Reputation: 157
How can I show records that are due to expire in two months?
I have tried using DATEADD
but I appear to have the logic code incorrect.
GETDATE() >= DATEADD(MONTH,-2, cycles.[NEXT-DATE])
Any code on how I can do this?
Thanks,
Upvotes: 0
Views: 529
Reputation: 66
I guess it should be sth like this
DATEDIFF(DAY, DATEADD(MONTH, 2, GETDATE()), cycles.[NEXT-DATE]) < 0
Upvotes: 1
Reputation: 2205
Your code gives you records that have expiry date equal 2 months or more. You should change your condition. Draw a time line to visualize it (it's easier then to understand how it should look like).
GETDATE() >= DATEADD(MONTH,-2, cycles.[NEXT-DATE])
and GETDATE() <= cycles.[NEXT-DATE] --checking if date is in the future
Upvotes: 1