- var_dump: documentation ( source)
- time: documentation ( source)
- explode: documentation ( source)
<?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";