Speed up development with full-stack environments for every branch.

Learn More

How to calculate the difference between two dates [PHP]

708 Runs 4366 Views 1842 Copies


dipesh.parmar 55

published 4 years ago

<div style="margin-left:50px;">
  <h2>Calculate the difference between two dates</h2>
    we will use DateTime and DateInterval objects for this.
      create two date object named
    $date1 = new DateTime("2013-10-25");
    $date2 = new DateTime("2013-03-31");
      below code returns the difference between two DateTime objects
    $interval = $date1->diff($date2);

    echo "<strong>Difference :</strong> " 
          . $interval->y . " years, "
          . $interval->m ." months, "
          . $interval->d  ." days "; 
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).