Topic: change css at a specific time of day?

I've been exploring a "day" and "night" version of my style sheet.

In trying to automate it, i am working to integrate this code by applying it to the header:

Line 65 of header.php

<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />


<link rel="stylesheet" href="<?php

// Not sure about this part here, trying to establish the root

echo "/";

// Hours difference (+/-) your board is from the server's time
$offsetfromserver = 0;

$thehour = date('G') + $offsetfromserver;

if ($thehour >=6 && $thehour < 19) {
echo 'style/sheet1.css';
} else {
echo 'style/sheet2.css';

?>" type="text/css" media="screen" />

in theory it should work. As an if/else condition this works to display an image, or something else between these hours. But for some reason it's not functional for swapping the style sheet code.

What happens is upon application, all the css information is lost.

What am I doing wrong?


Re: change css at a specific time of day?

Tried another approach:

Adding this to the main template instead of the header, and addressing only the div id i want to change.

<div id="<?php

if (time('G') >= 6 && time('G') < 19) {
echo 'daytime_id';
} else {
echo 'nighttime_id';


still results in the absence of this div. not even the else condition appears.

I am pretty sure I have the "time()" syntax wrong, but didn't think that would block the else from working...


Feeling ambitious, but incompetent.