3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/Toronto'); $start_day = 'tue'; $start_time = 181300; $end_day = 'fri'; $end_time = 134500; $startDate = DateTime::createFromFormat ( 'D His', $start_day . ' '. $start_time); $endDate = DateTime::createFromFormat ( 'D His', $end_day . ' '. $end_time); $startHour = $startDate->format('G'); //24-hour format of an hour without leading zeros $startDay = $startDate->format('N'); //numeric representation of the day of the week $endHour = $endDate->format('G'); //24-hour format of an hour without leading zeros $endDay = $endDate->format('N'); //numeric representation of the day of the week //We Need to check the time is between Tuesday 6PM ( 2 and 18 for $startDay and $startHour respectively ) to Friday 6PM ( ( 5 and 18 for $endDay and $endHour respectively )) if ( $startDay >= 2 && $endDay <= 5 && $startHour >= 18 and $endHour <= 18 ) { echo 'Within Time Range'; } else { echo 'Outside Range'; }
Output for 7.1.25 - 7.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
Within Time Range

preferences:
169.92 ms | 407 KiB | 5 Q