MySQL DATE_ADD INTERVAL

Dee1983 picture Dee1983 · Feb 25, 2012 · Viewed 8.5k times · Source
    mysql_query("UPDATE tablename SET date = DATE_ADD(DATE(NOW() + INTERVAL 1 WEEK), INTERVAL 17 HOUR), INTERVAL 30 MINUTE)
        WHERE idevent = '2'")
or die(mysql_error());

I want to add 7 days to the date, but have the time aspect of datetime manually set. I have the code above, which works for the hour, but as soon as I add minutes it errors saying SQL syntax error.

Any ideas?

Answer

Michael Berkowski picture Michael Berkowski · Feb 25, 2012

You need another DATE_ADD() at the front of that expression, since you're doing two additions.

mysql_query("UPDATE tablename SET date = DATE_ADD(DATE_ADD(DATE(NOW() + INTERVAL 1 WEEK), INTERVAL 17 HOUR), INTERVAL 30 MINUTE) WHERE idevent = '2'");
//-------------------------------------^^^^^^^^^^^^^^^^^^^^