Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWebsite Automation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

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.

&copy; <?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:

&copy; 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.

&copy; <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:

&copy; <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

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC