Domanda

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!

È stato utile?

Soluzione

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

Altri suggerimenti

to_date = DATE_ADD(from_date, INTERVAL 28 DAY)

Check this question out, it does what you want.

You can use the DATE_ADD() function:

... WHERE DATE(DATE_ADD(eventdate, INTERVAL -1 DAY)) = CURRENT_DATE
It can also be used in the SELECT statement:

SELECT DATE_ADD('2010-05-11', INTERVAL 1 DAY) AS Tomorrow;

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top