user3306489
user3306489

Reputation: 157

T-SQL show records that are due to expire in two months

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

Answers (2)

Jacek Drozd
Jacek Drozd

Reputation: 66

I guess it should be sth like this

DATEDIFF(DAY, DATEADD(MONTH, 2, GETDATE()), cycles.[NEXT-DATE]) < 0

Upvotes: 1

M. Kanarkowski
M. Kanarkowski

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

Related Questions