I am trying to create a PHP query to delete SQL table rows if the CURDATE column is a year old.

For example, if the current date is 2014/04/1 and the SQL table row's curdate column's data is 2013/04/1 than that table row will be deleted.

For a code example, I am looking for something like:

$sql = "DELETE * from Orders WHERE Curdate == 'CURDATE - 365 days'";
$query = mssql_query($sql);

From my knowledge the above code wouldn't work as it is not correct syntax, but is there something with working syntax that is similar to that?

All help is greatly appreciated.

有帮助吗?

解决方案

Try this:

DELETE * from Orders WHERE Curdate == DATE_SUB(curdate(), INTERVAL 1 YEAR)

Read more here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top