End-of-Year Copyright Year Number Change
If you have your web pages set up to automatically update the copyright year, then soon after the beginning of the new year do a spot check to verify everything is working. If yes, you're good to go.
Otherwise, this article is for you. It describes how to set up an automatic update of the year number in a copyright statement.
There is a JavaScript method and a PHP method. Each is self-contained — no external files or coding required.
It is my understanding that the format of a legal copyright line in the USA (but do consult your own legal advisors) is like this:
("Copyright" or "©") (year number or year number range) (copyright owner)
(The © character can be created on a web page with the ©
HTML entity.)
Example copyright line:
© 2011-2024 Will Bontrager Software LLC
Other countries may have different legal requirements.
The JavaScript or PHP code, whichever you prefer, probably can be used for any country's legal copyright line where only the year number needs automatic updating.
An important note: For PHP, the year number is obtained from the server where the web site is hosted. For JavaScript, the year number comes from the browser's clock at whatever time and time zone it has been set for.
Let's do the PHP updating code first. Then the JavaScript.
Auto-update Copyright Year With PHP
If you have had your website more than a year, probably you'll want a past year number to indicate a range. I'll present an example of that in a moment. First, the most simple example.
This copyright line automatically publishes the year number
© <?php echo(date("Y")) ?> Name
(The PHP code is colored blue.)
This is the result:
© 2024 Name
Now, for a past year to indicate a range of years for the copyright. We'll assume 2011 is the year number when the range begins.
© 2011-<?php echo(date("Y")) ?> Will Bontrager Software LLC
(PHP code is blue.)
This is the result:
© 2011-2024 Will Bontrager Software LLC
The year number is obtained from the server where the web site is hosted and will change when the clock at the server indicates the new year is here.
Auto-update Copyright Year With JavaScript
As before, the first example is the most simple.
This copyright line automatically publishes the year number
© <script>document.write(new Date().getFullYear());</script> Name
(The JavaScript code is colored blue.)
This is the result:
© Name
Now, for a past year to indicate a range of years for the copyright. As before, we'll assume 2011 is the year number when the range begins.
Because a script
tag introduces a space, and we don't want that in the range, the "2011-" is written with the JavaScript.
© <script>document.write("2011-" + new Date().getFullYear());</script> Will Bontrager Software LLC
(JavaScript code is blue.)
This is the result:
© Will Bontrager Software LLC
The year number is obtained from the site visitor's computer/device clock at whatever time and time zone it has been set for.
Besides choosing PHP or JavaScript by personal preference, there are these considerations.
-
PHP — The year is obtained from the server's clock. The code is the shortest. The code works only on PHP web pages.
-
JavaScript — The year is obtained from the clock on the computer/device where the browser is running, which is subject to how the user set it. The code works on pretty much all web pages.
Whichever method you choose, it should automatically update the copyright year number for you — year after year after year.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager