Hi All,
I am trying to setup a simple website that changes colors during the day. I have made a switch statement for this. But the statement only pick the second option. No matter the time of day. What is wrong with this code? In this case it will only take “Dawn” state because it is the second.
[php]
$date = date(“G”);
switch (true) {
// NIGHT 8pm - 4am
case ($date <= 4 || $date >= 20) :
$maincolor = ‘#40AFB5’;
$darkcolor = ‘#08666b’;
$backgroundcolor = $bgcolor;
$backgroundimage = ‘bg’;
$stateofday = ‘Night’;
break;
// DUSK 5pm - 8pm
case ($date <= 20 || $date >= 17) :
$maincolor = ‘#0ea2e8’;
$darkcolor = ‘#016493’;
$backgroundcolor = $bgcolor;
$backgroundimage = ‘bg’;
$stateofday = ‘Dusk’;
break;
// DAWN 4am - 7am
case ($date <= 7 || $date >= 4) :
$maincolor = ‘#d80e0c’;
$darkcolor = ‘#810503’;
$backgroundcolor = $bgcolor;
$backgroundimage = ‘bg’;
$stateofday = ‘Dawn’;
break;
// DAY 7am - 5pm
default:
$maincolor = ‘#f4b41b’;
$darkcolor = ‘#996d02’;
$backgroundcolor = $bgcolor;
$backgroundimage = ‘bg’;
$stateofday = ‘Day’;
}
[/php]