solarisuser Posted May 31, 2007 Share Posted May 31, 2007 Hi All, I think I'm overcomplicating things so I thought I'd ask if there is a better way to subtract two dates. Plus, my way is not very accurate. Its a few days off... Both dates come from MySQL in the format "YYYY-MM-DD". $end_date = $row['end_date']; // (2007-10-10) $ts = time(); $start_date = date("Y-m-d", $ts); // (2007-05-28) $end = round(strtotime("$end_date")/84000,5); $exploded = explode(".",$end); $end_date = $exploded[0]; $start_date = round(strtotime("$start_date")/84000,5); $exploded = explode(".",$start_date); $start_date = $exploded[0]; $expiration_in_days = abs($start_date - $end_date); Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/53677-solved-subtract-dates/ Share on other sites More sharing options...
Barand Posted May 31, 2007 Share Posted May 31, 2007 You could use mysql DATEDIFF SELECT DATEDIFF(CURDATE(), end_date) as expires_in_days FROM mytable Quote Link to comment https://forums.phpfreaks.com/topic/53677-solved-subtract-dates/#findComment-265394 Share on other sites More sharing options...
solarisuser Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks Barand, but with alot of records I figure it'd be quicker using PHP to calculate than MySQL when the record is already in memory. In any case, I managed to get it. Quote Link to comment https://forums.phpfreaks.com/topic/53677-solved-subtract-dates/#findComment-265707 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.