-4

I'd like to write a function that returns a boolean true if the request is being made between 8am and 5pm central timw monday-saturday, and false any other time. I know that I will probably be using date() and strtotime()but outside of that, I'm lost. Any pointers?

desired result

if (DuringBusinessHours()) {
    // execute this
} else {
   // execute this
}
drewwyatt
  • 5,989
  • 15
  • 60
  • 106
  • http://stackoverflow.com/a/1525937/1180785 – Dave Jun 02 '13 at 20:17
  • 4
    Have you at least looked at the documentation for the functions you've mentioned? –  Jun 02 '13 at 20:17
  • @TimCooper Yes, I have. If it is as simple as your cynicism suggests, wouldn't it have been easier to just answer my question, receive an up-vote, and be marked as the accepted answer? – drewwyatt Jun 02 '13 at 20:20
  • 1
    @anwyatt So which part of the documentation was unclear to you? – JJJ Jun 02 '13 at 20:24
  • 1
    Hi @anwyatt - don't be put off by the occasionally terse tone here. Respondents - myself included - are often a bit jaded by the number of people who ask questions without basic research, so it becomes easy to assume the same of everyone! In the `php` tag the level is alarmingly high, perhaps because it attracts a lot of beginner programmers. – halfer Jun 02 '13 at 21:18

1 Answers1

2

I would suggest something like this:

// create start and end date time
$start = new DateTime('8:00am');
$end = new DateTime('5:00pm');

// get the current time
$now = new DateTime();

// note that you can use the < > operators 
// to compare date time objects
if($now >= $start && $now < $end) {
    echo 'during business hours';
}
hek2mgl
  • 152,036
  • 28
  • 249
  • 266