<?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';
}
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Within Time Range