HOW TO: Automatically Update The Copyright Year

Copyright-YearManually updating the copyright year could be annoying to everyone. We need to change the copyright year every year. But there is a solution for this indeed. You can automatically update the copyright year using PHP and also using JavaScript.

These code snippets updates the copyright year automatically. JavaScript code works on any webpages whereas PHP code works only on PHP pages. But both they have their own advantages.

JavaScript Code Snippet

<script type="text/javascript">
now=new Date();
year=now.getFullYear();
</script>&copy; Copyright 2008-<script type="text/javascript">
document.write(year);
</script>

The output will be like this :

Β© Copyright 2008-2009

Note : You should update the starting year for your copyright year.

PHP Code Snippet

&copy; Copyright <?php
$then = 2007;
$now = date(’Y');
if ($then == $now)
echo $now;
else
echo "$then - $now"; ?>

You can also try this snipper for simplity of code

&copy; Copyright 2007 - <?php echo date('Y'); ?>

Note : You need to edit $then for setting it to the year your blog launched. The final year is automatically calculated using date() function of PHP.

26 thoughts on “HOW TO: Automatically Update The Copyright Year”

  1. its quite easy and usefull … Well most blogs have automatic updates of this year…
    like theme junkie… thanks pradeep…

    Reply
  2. He he he Nice one there. Simple Javascript to do the needy.

    DIdn’t get the thought of this until now πŸ˜‰

    Reply
  3. Prefer using PHP People.

    Javascript is not reliable as it runs in client side. Moreover, you can’t put this code in .htm(l) files in most of the servers as far as i know.

    So better config the server to hav a common footer that runs in php πŸ˜‰

    Reply
  4. I recently moved from Blogger to WordPress! I will need this script now! Thanks a ton!

    If you have any suggestions for a WordPress newbie like me, then feel free to tell me about it!

    Reply

Leave a Comment