简体   繁体   中英

How to check if current date time is within weekend period

I'm trying to create some kind of restaurant system that shows a different menu when it's the weekends.

The problem I'm having is how do I write my condition statement to decide the current date time is within Friday 5pm and Sunday 11:59pm. While I can quite easily determine the day of the week, I'm having problems when the time range comes into play.

Any help would be greatly appreciated please. Thanks!

Something like this ought to work:

$hourofweek = (date("N") * 24) + date("H");

if($hourofweek > (5*24 + 17)) {
   // it's the weekend
}

Note: date("N") follows a weird convention of Sunday being the last day of the week (7) so there's no need for a less-than check.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM