3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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";
based on TvNqH
Output for 5.6.0 - 7.3.0alpha1
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