Question

<?php 

$time = date('Hi');

if ($time > 0030) {
    echo "closed";
} elseif ($time >= 0800) {
    echo "open";
}
?>

This is the code i'm using for a client's website. In short it's a code that'll show if the client's business is open or not.

My client's working hours are between 8am to 12:30am.

I was wondering if there's an easier way of doing this or am I doing this right?

No correct solution

OTHER TIPS

Try this:

<?php 
date_default_timezone_set('Asia/Calcutta'); # set timezone according to your requirement
$now = new DateTime();
$start = new DateTime('today 08:00:00');
$end = new DateTime('tomorrow  00:30:00');
if ($start <= $now && $now < $end) {
    echo "open";
}
else{
    echo "close";
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top