Image Image Image Image Image
Scroll to Top

To Top

User Experience

Code of the Year

On 22, Feb 2007 | 3 Comments | In User Experience | By Ryan Feeley

Like most people, I have difficulty writing my first cheque of the new year. I always write the wrong year. Apparently, I am also like most web sites.

Many big, respectable and seemingly well-maintained sites show a previous year in their copyright footer. Some are painfully out of date.

If this was something that must be done manually, I could understand. But the content on a web page is not written with a Bic Grip Roller. It’s generated by a computer that knows the current year.

Here’s some code you can use to keep your copyright current. Examples for Perl, Python, etc. are appreciated!

In Javascript:

<script language="javascript" type="text/javascript">
var mydate = new Date();
var year= mydate.getYear();
if (year<2000){year+=1900};
if (year>2100){year-=1800};
var time = ( year );


<?php echo date("Y");?>

In parsed HTML (aka SHTML, must be enabled in Apache):

<!--#config timefmt=" %Y" -->
<!--#echo var="DATE_LOCAL" -->

In Java (JSP, thanks to Tim!):

<%= (new SimpleDateFormat("yyyy")).format( new Date() ) %>

In Smalltalk (thanks to Tim!):

^Date today year asString

In Ruby (thanks to Scott Boms):

add the following to a helper (eg. application_helper)

def copyright_year t = t.year end

then in the view file, just put <%= copyright_year %>


  1. Dan S

    In Django it’s:

    {% now “Y” %}

  2. Straight Python: import datetime print

    In Pylons: ${}

    Of course it’s super-easy to make your own webhelpers so that they’re as short as ${h.year}.

  3. mARK

    if the content of a page doesn’t change, then the copyright year shouldn’t either. if someone wants to challenge a copyright claim in court they can say the true date of the content can’t be determined.

Submit a Comment