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 www.dingdong.com in 2009 and in the footer of all the web pages in www.dingdong.com, there’s this line that says ‘Copyright © 2009, www.dingdong.com’.
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, www.dingdong.com.
Upon scrolling down, you see that the footer says ‘Copyright © 2009, www.dingdong.com’. You’re like, ‘Hello…? It’s already 2010 now…?!’ and you get a little bit angry. And then you remembered that you’ve got www.hi.com, www.byebye.com, www.iloveyou.com 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:
2019
So integrating HTML and PHP, this code below…
Copyright © <?php $yr = getdate(date("U")); print("$yr[year]"); ?> AzharKamar.com
Will show:
Copyright © 2019 AzharKamar.com
Like 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!
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!!
Nice. Thanks for typing this. Its always awesome to see someone help out the community.
thanks, very well written article, found it through a random yahoo search and i shared it on my twitter!
I just put into favorites the site. Good news.
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?
January 5th, 2011
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. :)
Yup! Thanks friend.
Good stuff..Was looking for this on Google and found your site. Works like a charm!The PHP codes are better..
January 20th, 2011
Anonymous replied:
Thanks Garcia! And yes, I prefer PHP too.