简体   繁体   中英

How to Delete MSSQL Table Rows if they are Older than One Year

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM