Time Dependant CSS with PHP
I am working on a website project that has a big sky in the header and thought it would be cool to have time dependant css files, replacing the header background image in each. After looking around at most of the javascript solutions I found a little snippet of php in which I got my brother mike to expand upon for me to add a sun down and a sun up style sheet as well.
- between 9 pm and 6 am uses night.css
- between 7 pm and 9 pm uses sundown.css
- between 6 am and 8 am uses sunup.css
- everything else 8 am to 7 pm is day.css
<link rel=”stylesheet” href=”<?php $currenttime = date(H);
if ($currenttime >= 21 OR $currenttime < 6) echo ‘/css/night.css’;
else if ($currenttime >= 18 AND $currenttime < 21) echo ‘/css/sundown.css’;
else if ($currenttime >= 6 AND $currenttime <echo ‘/css/sunup.css’;
else echo ‘/css/day.css’;?>” type=”text/css” media=”all” />
The Best part about this method is it requires no javascript just good old PHP.

