chongzixin
chongzixin

Reputation: 1981

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!

Upvotes: 0

Views: 637

Answers (1)

mimicocotopus
mimicocotopus

Reputation: 5600

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.

Upvotes: 3

Related Questions