How Do You Build a Self-Updating Copyright Notice?

Many websites have a copyright notice in their footer. Here’s how to create one that updates itself with every new year.

The standard format seems to be the copyright sign, followed by a range from the year the website’s owner was established, to the current year.

© 1900 - 2017 My Organization Inc.

If both the start and current year are the same, only one year is used in the notice:

© 2017 My Organization Inc.

The logic is pretty easy to implement in several languages:

Liquid

Figuring this out with Liquid templating tags required a bit of experimentation, so I’m showing the code snippet for this language first.

1
2
3
4
5
6
7
8
9
{% assign start_year = '1900' %}
{% assign current_year = {{site.time | date: '%Y'}} %}
        
<span class="copyright">
    &copy;{{ start_year }}
    {% if current_year != start_year %}
         - {{ current_year }}
    {% endif %}
</span>

JavaScript

A much shorter (yet less readable and customizable) version of the code below is available from Update Your Footer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var organization = 'My Organization Inc.';
var startYear = 1900;
var currentYear = new Date().getFullYear();
var notice = '&copy; ';

if ( startYear == currentYear ) {
    notice += startYear;
} else {
    notice += startYear + ' - ' + currentYear;
}

notice += ' ' + organization;

document.write( notice );

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

$org_name = 'My Organization Inc.';
$start_year = '1900';
$current_year = date('Y');

if ($start_year == $current_year) {
    $notice = "&copy; $start_year $org_name";
} else {
    $notice = "&copy; $start_year - $current_year $org_name";
}

echo $notice;

?>

How do you implement dynamic copyright notices in your language? Do you know a better way to implement this? Let me know at rico@mossesgeld.com.