Hello,
Trying to write a purge function that will remove all records older than 7 days.
Looked at $this::model()->deleteAll()
But am stumped.
Can someone help me?
Thanks
Hello,
Trying to write a purge function that will remove all records older than 7 days.
Looked at $this::model()->deleteAll()
But am stumped.
Can someone help me?
Thanks
did you try deleteAllByAttributes ?
http://www.yiiframework.com/doc/api/1.1/CActiveRecord#deleteAllByAttributes-detail
'delete from searchlog where date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()'
Trying to figure out the syntax for the above code when using deleteAll or deleteAllByAttributes.
try this (not tested):
$criteria=new CDbCriteria;
$criteria->addBetweenCondition("date","DATE_SUB(NOW(), INTERVAL 7 DAY)","NOW()")
Model::model()->deleteAll($criteria);
Thank you, will test tonight.
This will not delete all records older than 7 days, but all records of the last 7 days…
To delete all records older than 7 days it must look like:
// delete from searchlog where date < DATE_SUB(NOW(), INTERVAL 7 DAY)
$criteria->addCondition("date < DATE_SUB(NOW(), INTERVAL 7 DAY)");
No between condition is needed.
Marco