dotcom22
dotcom22

Reputation: 259

Mysql query countdown until date expiration

I have this query:

SELECT DATE_FORMAT( expiry_date, '%d.%m.%Y' ) FROM my_subscriptions WHERE user_id = '[user_id]'

which extract expiry date of users subscription plan of my site. Now I would like use another query who count and extract remaining days before reach expiration date. I'm not a sql guru and have poor knowledge about. Any suggestions ?

Upvotes: 0

Views: 1462

Answers (2)

Filipe Silva
Filipe Silva

Reputation: 21657

You would do

SELECT DATEDIFF(expiry_date,NOW()) AS days 
FROM my_subscriptions WHERE user_id = '[user_id]';

Upvotes: 4

DevlshOne
DevlshOne

Reputation: 8457

SELECT DATEDIFF(expiry_date, CURDATE()) AS days_until_expire FROM my_subscriptions WHERE user_id = '[user_id]'

Upvotes: 2

Related Questions