Updating dates in a MYSQL DB

Hi everybody,
I have dates in my database, in the format, yyyy-mm-dd. If I want to add a week to the date ( 604800 seconds ), is there there a php function to allow this, or must I extract the date from the database, convert it to a timestamp and then add the seconds and update the database?

Thanks in advance

It would depend on what datatype your date field is, but, if it’s a string you could use…

UPDATE table SET date_field = DATE_FORMAT(DATE_ADD(STR_TO_DATE(date_field, '%Y-%m-%d'),  INTERVAL 1 WEEKS), '%Y-%m-%d')

I guess if it’s DATETIME, you could use…

UPDATE table SET date_field = DATE_ADD(date_field,  INTERVAL 1 WEEKS)

I don’t do SQL, so it might be off, but the logic/functions are there. :wink:

UPDATE table SET somedate = DATE_ADD(somedate, interval 1 week)

UPDATE daTable SET somedate = somedate + INTERVAL 1 WEEK

Thanks for the tips guys, just realized its more of a SQL question…

Just for the sake of education, if you ever need to add a week to a date in PHP for display purposes…

echo date('Y-m-d', strtotime('+1 week', $date_string));