PHP function to get the number of days between two dates

12 sec read

The below function can be used to calculate the difference in days between two dates

USAGE:

/**
 * Getting the number of days between two dates
 * 
 * @param string $date1 yyyy-mm-dd
 * @param string $date2 yyyy-mm-dd
 * @return integer
 */
function getDiffInDays($date1,$date2){
     $datediff = strtotime($date1)-  strtotime($date2);
     return floor($datediff/(60*60*24));
}
$days = getDiffInDays('2013-02-15','2013-01-26');

Last Updated On March 22, 2018

Leave a Reply

avatar
  Subscribe  
Notify of