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 Quote Link to comment 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)"; Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.