graham23s Posted September 1, 2008 Share Posted September 1, 2008 Hi Guys, say i have a time in mysql: 2008-09-01 13:27:31 how would i work out in PHO 24 hours later? what i want to do is if a customer adds something into there shopping cart and dont buy within 24 hours i run a query to delete! thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/122278-working-out-time/ Share on other sites More sharing options...
thebadbad Posted September 1, 2008 Share Posted September 1, 2008 strtotime() <?php $time = '2008-09-01 13:27:31'; $next = date('Y-m-d H:i:s', strtotime("$time + 24 hours")); ?> Link to comment https://forums.phpfreaks.com/topic/122278-working-out-time/#findComment-631406 Share on other sites More sharing options...
graham23s Posted September 1, 2008 Author Share Posted September 1, 2008 Thanks mate! does this look ok? <?php // Auto delete the users cart 24 hours after making selection $q_times = "SELECT `date` FROM `fcp_orders`"; $r_times = mysql_query($q_times); $a_times = mysql_fetch_array($r_times); $times = $a_times['date']; $time = $times; $next = date('Y-m-d H:i:s', strtotime("$time + 24 hours")); // delete query $q_delete = mysql_query("DELETE FROM `fcp_orders` WHERE `date` => $next"); ?> id test it but i need to wait 24 hours lol cheers Graham Link to comment https://forums.phpfreaks.com/topic/122278-working-out-time/#findComment-631411 Share on other sites More sharing options...
thebadbad Posted September 1, 2008 Share Posted September 1, 2008 No problem. I'm not sure you can compare the date fields with =>, but I could be wrong. If you can't, I'm sure there's a command for comparing dates in MySQL. Else calculate the timestamps in the query, and compare those. Also, shouldn't you surround $next with single quotes, inside the query? Link to comment https://forums.phpfreaks.com/topic/122278-working-out-time/#findComment-631449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.