I have two dates like this, how to calculate left days in between dates using php.
$date1='2016-12-26';
$date2='2017-03-21';
I have two dates like this, how to calculate left days in between dates using php.
$date1='2016-12-26';
$date2='2017-03-21';
 
    
    Refer to date_diff .Try this:
$d1 = new DateTime($date1);
$d2 = new DateTime($date2);
$diff = $d2->diff($d1);
echo $diff->days;  // 85
 
    
    You can use this if date_diff doesn't work.Use this function if you want to get the dates between the date1 and date2 or if u want the left days between the two given dates then you can increment a number like $i below and u ca return the $i value.
    function date_range($date1, $date2, $step = '+1 day', $output_format = 'Y-m-d') {
      $dates = array();
      $current = strtotime($first);
      $last = strtotime($last);
      $i=1;
      while( $current <= $last ) {
        $dates[] = date($output_format, $current);
        $dateq = date($output_format, $current);
        $current = strtotime($step, $current);
        $i++;
      }        
      //return $dates; if u want the dates 
      return $i; //if u want the count of dates between the tow given dates
    }
Hope this help you..
