We have decided to start publishing some website design tricks, there won’t be anything ground breaking here, and nothing that a half decent web designer should not already know, but it may be useful for those hobbyists, or bloggers that enjoy tinkering with their website
Something that is often over looked on a website is the date. A website that has 2005, or worse 1995-1999 on it instantly looks out of date. It is also something that is often visible in the New Year, with some websites keeping the year before’s date on their website for weeks, or even months.
It’s understandable, for most people changing the date means getting a website designer to change it, or tinkering around with the code on all of the pages. There is however an easier way of keeping your website date up to date. It won’t help you the first time (you’ll still have to replace the code on all pages with the code below), but once done you won’t have to change the date ever again!
PHP
If your website or blog uses PHP (the pages will end in .php, WordPress uses PHP), then it is very simple
If your footer code containing the date looks something like this:
© 2006-2010 Horizon Web Development
<p>&;copy; 2006-2010 Horizon Web Development</p>
Then you simply need to change it so that the code is as below:
© 2006-2010 Horizon Web Development
<p>© 2006-<?php echo date(‘Y’);?> Horizon Web Development</p>
That code merely gets the current year and inserts it into the space. Simple. Those not using PHP can use JavaScript to alter the date, but it is slightly more complicated.
JavaScript
Using the same example above, you’ll need to add slightly more code, like so:
© 2006-2010 Horizon Web Development
<p>&;copy; 2006-<script>var now = new Date(); var theyear = now.getFullYear(); document.write(theyear);</script> Horizon Web Development</p>
This works in a similar way to the PHP code, getting the current year and printing it out onto the screen. Once again if you replace the current date with this code, you’ll never have to change the current date on your website again.
The only downside to the latter method is that it will only work if the visitor has JavaScript enabled (it is enabled by default in all browsers), if it isn’t enabled, the visitor will just see a space, e.g. 2006- Horizon Web Development.
Once done, those days in early January where you keep reminding yourself that you really must get around to changing the date, will be a thing of the past.