End-of-year Automatic Copyright Change
If you manually update the copyright dates of your web pages, now might be a good time to automate the job. For new websites, it is prudent to set this up right from the start.
This article describes how to set up an automatic update of the year number within a copyright statement. The copyright statement itself may need to be different than the examples used, depending on legal requirements where you are resident. (The © character can be created on a web page with the ©
HTML entity.)
There is a JavaScript method and a PHP method. Each is self-contained — no external files or coding required.
When 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.
Example copyright line:
© 2001-2025 Will Bontrager Software LLC
In the above example line, the second year number should be the current year number. It automatically increments every year at midnight on the 1st of January.
A consideration: If you use the PHP in this article, the year number is obtained from the server where the web site is hosted. If you use the JavaScript in this article, 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 code first. Then the JavaScript.
Auto-update Copyright Year With PHP
One way to publish the current year number with PHP is by using this code:
<?php echo(date("Y")) ?>
The above will print the 2025
year number.
The following line will print the current year number within a copyright statement.
© <?php echo(date("Y")) ?> Will Bontrager Software LLC
The PHP part of the above source code is colored blue. The source code will print this line:
© 2025 Will Bontrager Software LLC
To publish a range of year numbers, this can be used:
© 2001-<?php echo(date("Y")) ?> Will Bontrager Software LLC
That will publish;
© 2001-2025 Will Bontrager Software LLC
With PHP, 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
One way to publish the current year number with Javascript is by using this code:
<script>document.write(new Date().getFullYear());</script>
The above will print the year number.
The following line will print the current year number within a copyright statement.
© <script>document.write(new Date().getFullYear());</script> Will Bontrager Software LLC
The JavaScript part of the above source code is colored blue. The source code will print this line:
© Will Bontrager Software LLC
To publish a range of year numbers, this can be used:
© <script>document.write("2001-" + new Date().getFullYear());</script> Will Bontrager Software LLC
The reason the "2001-" is published with JavaScript is because the script
introduces a space, and we don't want a space immediately after the hyphen character. The above source code will print this line:
© Will Bontrager Software LLC
With JavaScript, the year number is obtained from the site visitor's computer/device clock at whatever time and time zone it has been set for.
Whichever method you choose, PHP or JavaScript, it automatically updates the copyright year number for you — year after year after year.
(This content first appeared in Possibilities newsletter.)
Will Bontrager