White Wave Designs

How to Automatically Update Your Copyright Year with Javascript

Wouldn't it be nice to be able to scratch even one item off your New Year's webmaster checklist? Well, now you can! No more manual updating of the copyright years with this niftly little script.

Cut and paste this code into your file. Since this is javascript, be sure you are in code view (as opposed to design view) when you do this.

Replace both sets of "xxxx" with the first year the website was published. I first published White Wave Designs in 2003, so my code looks like this:

Copyright © 2003
<script language="JavaScript">
var d=new Date();
if (yr!=2003)
document.write("- "+yr);

And the copyright in my footer looks like this: Copyright © 2003 .

What makes this script so convenient is that you can put it in a new site, and then forget about it! This line of code tells the browser to print the dash and the current year only if the original year is not the current year:

if (yr!=xxxx)

What it really means is:

if (this year is not equal to the first year)...

What about the people who don't have javascript turned on, you ask? The will see your copyright statement as if you hadn't ever bothered to update the year:

Copyright © 2003.

Not a bad price to pay for not having to worry about it anymore. So, put this on your sites and have one less thing to do on New Year's Day!

Questions? It's not working the way you thought it would? Like it? Please email me and let me know!