View Full Version : Add days to Date column
keith1995
10-19-2009, 08:21 PM
We have a column that has a stored date in 'date' format (yyyy-mm-dd). We need to update all of the data in this column to add 60 days to date. What should the query be?
Old Pedant
10-19-2009, 09:08 PM
UPDATE table SET columnname = columname + INTERVAL 60 DAY;
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
I *think* that MySQL assumes an interval of DAY if you omit it. So I *think* you could do it as simply
UPDATE table SET columnname = columname + 60;
But whatever.
keith1995
10-19-2009, 10:12 PM
Hmmm, that didn't work for some reason.
UPDATE news_articles SET date_full = date_full + INTERVAL 60 DAY
The result is 0 row(s) affected.
Old Pedant
10-20-2009, 01:08 AM
maybe your column is not a datetime column??
What is it's data type? Dump the table schema to find out.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.