petroz Posted September 17, 2009 Share Posted September 17, 2009 Hi Guys, I have a cron job running that is supposed to update all records where the 'time' field is older that ten days. It seems to updating the entries within just a few hours of the timestamp instead of ten days. Please help!! <?php include 'db.php'; $time = date("YmdHis"); $requests = "UPDATE requests SET status=4 WHERE time <= ($time-864000)"; $requestsresult = mysql_query($requests) or die("Invalid remove query: " . mysql_error()); ?> Thanks, P Link to comment https://forums.phpfreaks.com/topic/174624-update-record-where-timestamp-is-10-days-old/ Share on other sites More sharing options...
DJTim666 Posted September 17, 2009 Share Posted September 17, 2009 Your $time variable should be time(). That'll fix your problem. Link to comment https://forums.phpfreaks.com/topic/174624-update-record-where-timestamp-is-10-days-old/#findComment-920281 Share on other sites More sharing options...
petroz Posted September 17, 2009 Author Share Posted September 17, 2009 Thanks DJTim, Will that be the case even if I am storing the timestamp in mysql like so "2009-09-16 23:22:06"? Thanks, P Link to comment https://forums.phpfreaks.com/topic/174624-update-record-where-timestamp-is-10-days-old/#findComment-920286 Share on other sites More sharing options...
DJTim666 Posted September 17, 2009 Share Posted September 17, 2009 No, you'll have to change the way you're storing the time in your database if you want to run the query like that. mktime() should be able to help you convert. Edit: I always use a UNIX timestamp to insert dates into the database. It's much more flexible than having an actual date stamp. Link to comment https://forums.phpfreaks.com/topic/174624-update-record-where-timestamp-is-10-days-old/#findComment-920301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.