Question

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.

Was it helpful?

Solution

Try this:

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

Read more here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top