用PHP开放时间

时间:2013-07-31 15:43:44

标签: php date time

我有一个想要在线披萨店的客户,他也不希望客户在营业时间之后下订单 - 当然。我为此制作了一个简单的脚本,我想我可能会与未来想要的人分享。

1 个答案:

答案 0 :(得分:3)

<?php
    date_default_timezone_set('Europe/Stockholm'); // timezone 

    $weekday = date(l); // today
    //print $weekday; // Debug
    //print date("H:i"); // debug

    // Set open and closing time for each day of the week
    if ($weekday == "Friday") {
        $open_from = "11:00";
        $opten_to = "21:45";
    }
    elseif ($weekday == "Saturday" || $weekday == "Sunday") {
        $open_from = "12:00";
        $open_to = "21:45";
    }
    else {
        $open_from = "11:00";
        $open_to = "20:45";
    }

    // now check if the current time is before or after opening hours
    if (date("H:i") < $open_from || date("H:i") > $open_to ) {
        print "Closed!";
    }

    // show the checkout button
    else {
        print "Open!";
    }
?>