I wanted to know if this is possible in Mysql and if so how.

I am running an ecommerce site and when a user purchases something - on the thank you page - I want to give them a discount code with a message saying - the discount code will expire in 4 hours or 6 hours or 24 hours.

Basically the logic is - once the payment is made - a unique discount code is created and inserted in this discount table as shown below

discount_id | user_id | discount_code | is_active | date_created
    101     |   21    |   50$OFF      |    Y      | 9/21/2012 13:00:00 

So once the 2 hours are up - I want the trigger or event to automatically execute and change the is_active status to N

discount_id | user_id | discount_code | is_active | date_created
    101     |   21    |   50$OFF      |    N      | 9/21/2012 15:00:00 

Thanks in advance

有帮助吗?

解决方案

It would be better to just store an outdate timestamp of the discount like discount_until.

That way you don't have to set anything.

It is the same as in the age of people. Store the birthdate in the DB, not the age, because the age can change every day.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top