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?
SELECT user_id FROM users WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) > last_logged_in_date
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With