Calculate expiry date 3 months from now on MYSQL

So I have been given just the expiry dates for my loyalty cards, I need the query to display all the customers whose card will expire 3 months from the current systems date not hardcoded.

Lets say todays 2021-09-30, and the card expiry date for customer1 is 2021-12-12 and the customer2 is 2021-10-18. SO the query will display the name of the customer1 because its card is expiring in the 3rd month.

I have tried a few different methods but I can’t seem to find a solution

select DISTINCT c.customername from customers c WHERE c.CardExpDate now() and
datediff(now(),c.CardExpDate) <= -2 order by c.customerID;

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

you can try this

select c.*, timestampdiff(MONTH, now(3), CardExpDate) from customers c where
timestampdiff(MONTH, now(3), CardExpDate) = 3


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x