Auto Update the Copyright Year in a Website using PHP or JavaScript

22 Mar 2010

If you have been creating websites for years (or more than a year) I am pretty sure you have encountered the ‘copyright year’ issue. Let’s say you created a website in 2009 and in the footer of all the web pages in, there’s this line that says ‘Copyright © 2009,’.

Then comes the New Year of 2010 and when you wake up the next day after a night of celebration, you switch on the computer and visited your baby,

Upon scrolling down, you see that the footer says ‘Copyright © 2009,’. You’re like, ‘Hello…? It’s already 2010 now…?!’ and you get a little bit angry. And then you remembered that you’ve got,, and so on and so forth. So if you have 1,000 websites, you’re in big trouble baby.

Well here’s something that would help you a great deal.

Auto Update Copyright Year using PHP

For me, I prefer PHP to JavaScript because the script is much shorter and cleaner.

This piece of code below will return you the current year:
<?php $yr = getdate(date("U")); print("$yr[year]"); ?>
It will display:

So integrating HTML and PHP, this code below…
Copyright © <?php $yr = getdate(date("U")); print("$yr[year]"); ?>

Will show:
Copyright © 2019 AzharKamar.comLike the one in the footer of this page.

And that’s it for the PHP bit. Short and sweet. Now let’s go on to JavaScript.[adsense1]

Automatic Updating of the Copyright Year using JavaScript

Here’s the JavaScript code that will show the current year:
<script type="text/javascript">
var date_object = new Date();
var year = date_object.getYear();
if(year < 2000) { year = year + 1900; } document.write(year); </script>

Lengthy isn’t it? Use PHP then. ;-)

And…… That’s it! Good luck friends!

Author - Azhar Kamar
9 Comments Revolving around this Article
  1. Oh my goodness! Awesome article dude! Thanks,
    However I am having difficulties with your RSS. I don’t know the reason why I can’t subscribe to it.
    Is there anyone else getting similar RSS problems? Anyone that knows the solution will
    you kindly respond? Thanks!!

  2. Nice. Thanks for typing this. Its always awesome to see someone help out the community.

  3. escort says:

    thanks, very well written article, found it through a random yahoo search and i shared it on my twitter!

  4. beijing massage says:

    I just put into favorites the site. Good news.

  5. Don Slack says:

    I recently took over a website that was sadly neglected and it carried a sentence that said “This year we celebrate our 54th Anniversary…” The only problem was that it was currently the 62nd at the time. Is there a JavaScript or other program that will automatically change the number, including the 1st, 2nd, 3rd, 4th, etc. as the year changes?
    If not is there one that will change at a given date or the end of the year that will change from First, to second, to third, fourth, etc. annually?

    Azhar Kamar replied:

    I think it’s easier if you use PHP.
    Here’s the simple calculation:
    Current year – Year website founded = Anniversary

    Refer to my codes above. :)

  6. Azhar Kamar says:

    Yup! Thanks friend.

  7. Garcia says:

    Good stuff..Was looking for this on Google and found your site. Works like a charm!The PHP codes are better..

    Anonymous replied:

    Thanks Garcia! And yes, I prefer PHP too.

Write a Comment! NOW! :)

Current ye@r *