Skip to content
Advertisement

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;

Advertisement

Answer

you can try this

select c.*, timestampdiff(MONTH, now(3), CardExpDate) from customers c where
timestampdiff(MONTH, now(3), CardExpDate) = 3
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement