Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql and 30 days

i'm working on a site that handles free subscriptions and i will like to now how to cancel their subscriptions after 30 days inactivity, i know that this has to be done with cron-jobs but i have no idea on how to count 30 after the last time the user logged in?

like image 455
Bruce Avatar asked Dec 13 '25 19:12

Bruce


2 Answers

SELECT user_id FROM users WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) > last_logged_in_date
like image 170
Novikov Avatar answered Dec 15 '25 09:12

Novikov


You need to use mysql DATE_ADD function

SELECT DATE_ADD('YOUR DATE', INTERVAL 30 day)

See mysql manual for more info http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add.

You can do it in 1 UPDATE statement

UPDATE yourTable SET active = 0 WHERE validity_date < CURRENT_DATE

And when they subscribe, you receive payment

UPDATE yourTable SET active = 1, validity_date = DATE_ADD(CURRENT_DATE, INTERVAL 1 MONTH) WHERE id = 'somekind of id'
like image 42
Alex Avatar answered Dec 15 '25 08:12

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!