3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Based on the following business hours: * (Note : I setup the hours for each day if they carry-over) * everyday is open from 09:00 AM - 12:00 AM * Sun/Sat open extra from 12:00 AM - 01:00 AM */ $apteka['MODE'] = "8:00 - 19:00"; $ex = explode(' - ',$apteka['MODE']); $open = $ex[0]; $close = $ex[1]; // current OR user supplied UNIX timestamp $timestamp = time(); // default status $status = 'closed'; // get current time object $currentTime = (new DateTime())->setTimestamp($timestamp); // create time objects from start/end times $startTime = DateTime::createFromFormat('H:i', $open); $endTime = DateTime::createFromFormat('H:i', $close); var_dump($startTime,$currentTime); // check if current time is within a range if (($startTime < $currentTime) && ($currentTime < $endTime)) { $status = 'open'; } echo "We are currently: $status";
Output for 5.6.0 - 5.6.27, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-11-08 08:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-11-08 16:06:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } We are currently: open

preferences:
91.52 ms | 403 KiB | 85 Q