我想使用PHP和MySQL来插入昨天的日子.所以我的想法是:
INTO chartValues SET timestamp='1353369600',`datetime`=DATEADD(d,-1,GETDATE())
但它不起作用:
1064 – You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘INTO chartValues SET timestamp=’1353369600’,
datetime
=DATEADD(d,GETDATE())’ at line 1
提前致谢
最佳答案
DATEADD和GETDATE()是SQL Server中使用的T-SQL函数.
你想在NOW()中使用DATE_ADD()或DATE_SUB()
INSERT INTO chartValues SET timestamp='1353369600',`datetime`= DATE_SUB(NOW(),INTERVAL 1 DAY)
Reference
DATE_SUB(date,INTERVAL expr unit)