Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
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 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

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

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

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

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

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
software index page

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