Finding the number of days between two dates

后端 未结 30 2505
心在旅途
心在旅途 2020-11-21 23:47

How to find number of days between two dates using PHP?

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 00:23

    $early_start_date = date2sql($_POST['early_leave_date']);
    
    
    $date = new DateTime($early_start_date);
    $date->modify('+1 day');
    
    
    $date_a = new DateTime($early_start_date . ' ' . $_POST['start_hr'] . ':' . $_POST['start_mm']);
    $date_b = new DateTime($date->format('Y-m-d') . ' ' . $_POST['end_hr'] . ':' . $_POST['end_mm']);
    
    $interval = date_diff($date_a, $date_b);
    
    
    $time = $interval->format('%h:%i');
    $parsed = date_parse($time);
    $seconds = $parsed['hour'] * 3600 + $parsed['minute'] * 60;
    //        display_error($seconds);
    
    $second3 = $employee_information['shift'] * 60 * 60;
    
    if ($second3 < $seconds)
        display_error(_('Leave time can not be greater than shift time.Please try again........'));
        set_focus('start_hr');
        set_focus('end_hr');
        return FALSE;
    }
    

提交回复
热议问题