Simple JQuery Copyright Year script

How many websites do you see that have a copyright line with last year in it?! It’s just a sign of a lazy web developer who can’t be bothered either to update it every year, or (much better) add a simple bit of JQuery to automatically display the current year in the copyright line!

Here’s a code snippet that I use on all my websites to do just that!

In the markup add your copyright statement like this:

&copy; My Company <span id="year"></span>. All rights reserved.

And then add this script to your page (after your JQuery reference):

<script>
  $(function(){
    var theYear = new Date.getFullYear();
    $(“#year”).html(theYear);
  });
</script>

The end result (assuming you’re reading this in 2015…) will look like this:

© My Company 2015. All rights reserved.

Posted in Code samples, JQuery Tagged with: ,
  • Pingback: Simple AngularJS Directive Copyright Year » Retromorrow()

  • Rob Horton

    Maff, thanks for writing this. I found it quite handy indeed and really enjoy little snippets like this. I forgot now, how I ran across your blog but I really enjoy your articles. I used the idea from your post for a little post of my own on how to do this with an Angular directive (hope you don’t mind). Keep up the great work!

  • Frank Jones

    Maff, I came across yours and Rob’s posts (great info BTW!) and wanted to share some other information I came across. Apparently, the year displayed is supposed to be the year of first publication (http://www.copyright.gov/circs/circ03.pdf). I personally prefer the updated copyright year, but thought I would share the info.

    • Hi Frank,

      Thanks for the link and you’re right that technically the copyright date is from when a piece of content is first published. However, most websites tend to go for the current year.

      I have seen some websites occasionally where they use a date range (e.g. 2012-2015) so maybe that could be an alternative solution?

      Thanks,

      Maff

  • MarkCanada2015

    Hmmm, I guess even after 15 yrs being a developer, mistakes happen.

    Your script is in error, it does not work and here is why.

    Error >> var theYear = new Date.getFullYear();

    Correct >> var theYear = new Date().getFullYear();

    // forgot to insert the open-close brackets after Date

    Error >> $(β€œ#year”).html(theYear);

    Correct >> $(“#year”).html(theYear); (or ) $(‘#year’).html(theYear);

    //Wrong type of quotes, if I copy and paste from your webpage. Your webpage displays “smart quotes” and jQuery scripts take those as an unacceptable script character.
    //For those who may not see these easily or have trouble changing them in your text editor, just replace the double quotes for single ones ‘ ‘ in this script.

    Now the script works.

    • matt

      Correct:

      $(function(){
      var theYear = new Date().getFullYear();
      $(‘#year’).html(theYear);
      });

      thnks mark

About Maff

Maff Rigby

I'm a certified .Net, Umbraco and AngularJS freelance developer with over 15 years experience in the IT industry. As well as writing code I love to teach; I run a number of workshops and 1-1 coaching sessions on Angular JS and Umbraco, and share what I know and learn here!

I’m social (ish)

Connect with me on LinkedIn, follow me on Twitter, or fail to find me on Facebook.