2

I want to calculate expiry date percentage.But my starting date and expirydate are in m/d/Y format.How I will find the number of days between starting date and ending date???This is my code...

 foreach ($result['query'] as $row) {
            $validitystart = $row->validitystart;
            $expirydate = $row->expirydate;
            $today = date('m/d/Y');
            $maxdiff = date_diff($expirydate, $validitystart);
            $diff = date_diff($expirydate, $today);
            $percentage = ($diff * 100) / $maxdiff;
        }
Fiona
  • 29
  • 6

1 Answers1

3

Among the hundreds of duplicates here on StackOverflow, you might have found something like this with a bit of searching

$date1 = DateTime::createFromFormat('m/d/Y', $date1);
$date2 = DateTime::createFromFormat('m/d/Y', $date2);

$diffDays = $date2->diff($date1)->format("%a");
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • please add reference if similar exists on this site (or elsewhere) – Nikos M. Apr 23 '15 at 07:16
  • [how to calculate the difference between two dates using php](http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php?rq=1) – Mark Baker Apr 23 '15 at 07:21