Jump to content

[SOLVED] subtract dates


solarisuser

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.