Update Your Copyright Year Automatically

Posted by Ryan Evans on January 3, 2020

Happy New Year!! 🎊

Did you remember to update your websites with the new copyright year?

Here’s how to set it up with javascript to auto-update every year, so you don’t have to worry about it…

All you need to do is make sure that your copyright statement is within <p></p> tags so this will be visible (not just within <footer> tags.
Then, you can add the javascript code inline within <script></script> tags.

One important thing to note first… if you didn’t already know, the getYear() method is deprecated, so you’ll need to use the getFullYear() method.

Here’s an example of what the code looks like:

   <p>website designed and built by Ryan Evans &copy;
      <script language="JavaScript" type="text/javascript">
         var today = new Date();
         var year = today.getFullYear();

And there you have it! Easy enough, right? Now if you add this little snippet to your sites, you won’t have to worry about updates every year! That <script> will display the current year right next to the &copy; copyright symbol.

Here’s wishing everyone a happy, healthy and prosperous new year!

Date.prototype.getFullYear() on MDN