Search code examples
mysqlmagentosql-updatemagento-1.7coupon

How can I UPDATE an expiration date in MySQL?


So, I need to reset the expiration dates for a bunch of coupon codes in our database. Our expirations dates are field "to_date" and are displayed as the following: to_date = '2013-04-14'

I need to set the to_date as 28 days after the from_date. So basically, something like this:

UPDATE salesrule
SET name = 'New coupon code', to_date = 'from_date + 28 days'

I know this would work for a simple int value, but I'm not sure how to do this give that the data displays as an actual date. I have no control over how the date itself displays, that's a built in Magento functionality.

I'm a big noob when it comes to MySQL, but I've done some research and I've found the format function: FORMAT(Now(),'YYYY-MM-DD') I have a feeling this may be the key... can someone point me in the right direction it terms of formatting or writing this command correctly? Thank you!


Solution

  • UPDATE salesrule
    SET name = 'New coupon code', to_date = DATE_ADD(from_date, INTERVAL 28 DAY);
    

    More info about the DATE_ADD() function here:

    https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add