Automate your website copyright date

Now that the new year is here, many of us will forget to change the © copyright date on our many websites. I’ve never really been sure why developers don’t always automate this process and therefore not have to worry about it at the change of the year. In this short post I will show you some quick methods of automating this process.
PHP
If your pages are written in PHP, all you need to do is to add this simple line in the place that you want the date to appear:
<?php print date('Y'); ?>
JavaScript
You can also use this simple JavaScript code to generate the year:
<script type='text/javascript'>document.write(new Date().getFullYear());</script>
.NET
The two methods for C# and VB are very similiar, but I’ve included both for completeness.
C#:
<%= DateTime.Now.Year.ToString() %>
VB:
<%= DateTime.Now.Year.ToString %>
Python
In Python, all you have to do is import the datetime library and add the line:
print datetime.date.today().year
Ruby
Thanks to Mark Embling, the Ruby code is:
<%= Time.now.year %>
Of course there are other languages and methods of doing this, these are just a few. I will add more as I find them or if others suggest that I should.
If you have any other suggestions of ways to automatically output the year on a webpage, or have other languages to suggest, please do so.

[...] This post was mentioned on Twitter by Ian Devlin, Michael Davis. Michael Davis said: RT @iandevlin: New blog post: automate your website copyright date: http://bit.ly/5zW0bX #webdesign #webdevelopment [...]
[...] This post was Twitted by iandevlin [...]
Good ol’ autodate. Good man. Doesn’t get enough of a mention…
Updated for Python.
[...] I had made a blog post about that very thing! Automate your website copyright date web :: blog :: twitter Reply With Quote + Reply to Thread [...]
Nice! However, I found a bug. Your PHP example has an incorrect PHP closing tag. Should be ‘?>’.
I found this when I cut and paste the code for my site.
stv
Doh, thanks. Fixed!
The .NET ones should only have the = at the start, and in the case of the C# one, no semicolon. Also, since it would always call ToString for you, you don’t actually need to include it. This would be more than fine:
Also, the Ruby variant (assuming you’re using ERB) would be:
< %= Time.now.year %>I can’t help but agree with you about this. I have used this trick on my own sites for some time, I don’t know why so many still do not. Nice to see a post about it to help others out who may not have considered it
Thanks Mark, the last = was actually supposed to be a %, but I mistyped. Corrected now.
It’s been wrong for a year, not good!
Thanks for the Ruby code, it’s been added.
I ran into this problem using the PHP option with strict error reporting: http://www.webmasterworld.com/php/3016276.htm (I’m using 5.2.6)
Yeah I’ve noticed that too in general with PHP5, anytime you use any date functions, it throws that in your face.
Thanks for pointing it out though.
[...] website copyright date iandevlin.com [...]
Realise this comment is a bit late but…
The main point of the copyright date is to assert priority, if someone posts identical material you want to be able to assert that you posted the material with an earlier date copyrighted 1998 (or whenever). If you code the date as above you get no protection at all as it shows the date the reader looks at the page, not the date that the page was written.
Hi David, very true, but then you could easily add in the date you wrote it. For example in PHP:
2009 - <?php print date('Y'); ?>That way it would read: 2009 – 2011
Why not just omit the date – all work is automatically your copyright isn’t it, whether you say so or not?
David – surely the date that’s on the page is so easily faked that it doesn’t actually offer any protection?
© 1963 Joe
It is indeed Joe, but since so many sites like to display it and keep it up to date, then this helps to do so.