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;
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.
you can try this
select c.*, timestampdiff(MONTH, now(3), CardExpDate) from customers c where timestampdiff(MONTH, now(3), CardExpDate) = 3