How can PHP handle the transition between days when checking for specific time ranges, such as 19:00 to 07:00?

When checking for specific time ranges that span across days, such as 19:00 to 07:00, we need to consider the transition between days. One way to handle this is by checking if the end time is before the start time, indicating that the time range crosses over to the next day. In such cases, we can split the time range into two separate ranges: one from the start time to midnight (23:59) and another from midnight to the end time. This ensures that the time range is accurately captured across days.

$start_time = strtotime('19:00');
$end_time = strtotime('07:00');

if ($end_time < $start_time) {
    // Time range crosses over to the next day
    $range1_start = $start_time;
    $range1_end = strtotime('23:59');
    
    $range2_start = strtotime('00:00');
    $range2_end = $end_time;
    
    // Check if current time falls within range 1 or range 2
    $current_time = strtotime(date('H:i'));
    if (($current_time >= $range1_start && $current_time <= $range1_end) || ($current_time >= $range2_start && $current_time <= $range2_end)) {
        echo "Current time is within the specified range.";
    } else {
        echo "Current time is outside the specified range.";
    }
} else {
    // Time range within the same day
    if (strtotime(date('H:i')) >= $start_time && strtotime(date('H:i')) <= $end_time) {
        echo "Current time is within the specified range.";
    } else {
        echo "Current time is outside the specified range.";
    }
}