You can make your open
and close
variables to include the day of the week. Have a look at this page of the manual:
http://php.net/manual/en/datetime.formats.relative.php
So open
could be 'Friday 22:00'
en close
could be 'Saturday 04:00'
. In PHP that would look like this:
$deal = array('open' => 'Friday 22:00',
'close' => 'Saturday 04:00');
echo 'deal open: '.date('Y-m-d H:i:s', strtotime($deal['open'])).'<br>';
echo 'deal close: '.date('Y-m-d H:i:s', strtotime($deal['close']));
For me this gives now:
deal open: 2014-10-24 22:00:00
deal close: 2014-10-18 04:00:00
Notice that the deal open
time is bigger that the current time. So you have to think about your if
conditions:
$open = strtotime($deal['open']);
$close = strtotime($deal['close']);
$now = time();
$dealIsOn = (($open > $now) && ($close < $now));
Which might seem counter-intuitive at first, but is correct.
Also notice that this system is quite flexible. With the same code you can select a day of the month. However, for a absolute dates you have to do another check:
$open = strtotime('2014-10-25 22:00:00');
$close = strtotime('2014-10-26 22:00:00');
$now = time();
$dealIsOn = (($open < $now) && ($close > $now));
So I would introduce a flag in the array indicating whether or not the open
and close
variables are absolute or relative.