Php: if now is business hours echo "we are open!"


I want to use php to put a note on a site saying “we are open, call now” (or whatever) if the time is between 7:30am and 4:00pm Monday to Friday.

Any help/direction is much appreciated.

if ( (int)date( 'N' ) < 6 ) {
    $h = (int)date( 'G' );
    if ( $h >= 7 && $h <= 16 ) {
        print 'Open!';

Course I skipped the minutes on purpose. I leave that to you.

Take a look at the documentation on for the date function - that has lots of information on how to get day of the week, current hour, minute, second etc.

Just remember that if you are only open for a few hours each day that you will always appear to be closed to those people who are always asleep during those hours.

Don’t forget holidays. It reflects badly if you say you are open during a holiday and you aren’t.

Just change your message to “We are probably open” and the holiday issue will be taken care of. Most of the time.

Holiday wont be an issue if he adds on the script what days his shop will be closed for say um the next year.

Thanks! Worked perfect.