Set up timed changes on a website

If you need to change content on your website in the future, and are running your page on an Apache web server, you can use Apache if statements to set up timed deployments based on the server time.

An example of how this can be handy is if you want to serve one include and then, after a certain period of time, serve another. Another example, change the css of your site by adjusting your <body id="style">.

Apache Logo

To do this you need to set a time format that is appropriate to your task; I have used just year, month, day, hour. If you need to be more specific you can find format examples here.

This is how to set your time format in Apache:
<!--#config timefmt="%Y%m%d%H" -->

Next you will use the Apache if statement to read the server time and serve different content based on the times you enter.

This line is the beginning of your code, use it to set the FINAL display period. It has the highest date number, it is the last condition in this statement that would be hit. In this case, we are resetting the body attribute:

<!--#if expr="$DATE_LOCAL >= 2009110700" -->
<body>

This line represents the change, we are altering the body attribute to read different CSS styles. If the first condition wasn’t hit, the server will check to see if the server time is greater than the time set here:

<!--#elif expr="$DATE_LOCAL >= 2009110600" -->
<body id="pageTakeover">

This line is the default display. The code here is served BEFORE any of the timed changes; in other words, if the time is not greater than either of the above conditions the server will show this content:

<!--#else -->
<body>

This line is simple, it ends the statement:

<!--#endif -->

Here what it looks like altogether:

<!--#config timefmt="%Y%m%d%H" -->

<!--#if expr="$DATE_LOCAL >= 2009110700" -->
<body>
<!--#elif expr="$DATE_LOCAL >= 2009110600" -->
<body id="pageTakeover">
<!--#else -->
<body>
<!--#endif -->