Poddy Posted May 29, 2008 Share Posted May 29, 2008 Hi, i want to run a cronjob at my application to delete records which are older than 2 months i tried using $sql = "SELECT * FROM `feeds` WHERE `timestamp`='DATE_SUB(CURDATE(), 60)'"; $result = mysql_query($sql) or die ('error' . mysql_error()); $row = mysql_fetch_assoc($result); print_r($row); note: this is a select because so far i cannot even select them.. this row returns me an empty result set the timestamp is feeded by the CURRENT_TIMESTAMP and is a timestamp type in the following format: 2008-05-29 14:53:38 thanks in advance to all helpers Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/ Share on other sites More sharing options...
effigy Posted May 29, 2008 Share Posted May 29, 2008 Try: $sql = "SELECT * FROM `feeds` WHERE `timestamp` <= DATE_SUB(CURDATE(), INTERVAL -2 MONTHS)"; Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/#findComment-552656 Share on other sites More sharing options...
metrostars Posted May 29, 2008 Share Posted May 29, 2008 TRy: $sql = "SELECT * FROM `feeds` WHERE `timestamp`='DATE_SUB(CURDATE(), INTERVAL 60 DAY)'"; $result = mysql_query($sql) or die ('error' . mysql_error()); $row = mysql_fetch_assoc($result); print_r($row); You missed out INTERVAL and DAY Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/#findComment-552659 Share on other sites More sharing options...
Poddy Posted May 29, 2008 Author Share Posted May 29, 2008 thanks for the replies the working code is: $sql = "SELECT * FROM `feeds` WHERE `timestamp` <= DATE_SUB(CURDATE(), INTERVAL 60 DAY)"; since month didn't want to work for some reason... Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/#findComment-552703 Share on other sites More sharing options...
effigy Posted May 29, 2008 Share Posted May 29, 2008 What about INTERVAL 2 MONTHS? I suppose the minus was pointless since DATE_SUB indicates what needs to be done. Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/#findComment-552705 Share on other sites More sharing options...
metrostars Posted May 29, 2008 Share Posted May 29, 2008 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-add I think the units are supposed to be singular. so it should be INTERVAL 2 MONTH . I might be wrong, but both might work. Link to comment https://forums.phpfreaks.com/topic/107808-solved-how-can-i-delete-records-older-than-2-months/#findComment-552779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.