Forum Moderators: open

Message Too Old, No Replies

Inserting in yesterday's date

         

ntbgl

7:59 am on Jul 28, 2008 (gmt 0)

10+ Year Member



I'm trying to insert a date into a mysql date cell.

At first I was trying to insert in the current date, so I used:

mysql_query("INSERT INTO table (date) VALUES (CURDATE())");

That worked fine. But then I needed to insert in yesterday's date. That didn't work so well (resulting error: "syntax error, unexpected T_STRING ").

mysql_query("INSERT INTO table (date) VALUES (DATE_SUB(CURDATE(),INTERVAL 1 DAY))");

Any ideas?

coopster

2:33 pm on Jul 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



table
(and
date
) is a reserved word [dev.mysql.com]. You should avoid using reserved words for table and column names otherwise you will need to employ special syntax when using them in query statements. In this case, if you put them both in backticks you should overcome your syntax error.

Demaestro

3:06 pm on Jul 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



mysql_query("INSERT INTO table (date) VALUES (DATE_SUB(CURDATE() - INTERVAL 1 DAY))");