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! 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 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. Link to comment https://forums.phpfreaks.com/topic/53677-solved-subtract-dates/#findComment-265707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.