November 18, 2009 by Dave Lauretti.
This one is simple. I’m placing this code snippets although I could have place it in web design because it also falls into that category.
The script. This little javascript snippet will automatically change the date beside your copyright – which is usually placed in the footer of your webpage.
Simply copy and paste the code below into your HTML webpage.
©<script type="text/javascript">
var theDate=new Date()
document.write(theDate.getFullYear());
</script> YourDomain.com. All Rights Reserved.
Now each new year, when the clock strikes 12, your copyright year will change to the current year. This code snippet is especially helpful to web designers who have quite a few clients and don’t want to feel obliged to go in and change the date each year.
Well, the above code does work but I’m going to add another piece of code below that works a little better. It’s written in PHP and will only work if your server supports PHP. The reason the following code is better for displaying the exact year as the date for your copy right is because even if JavaScript isn’t enabled in the users computer, the date will still display. Here’s the code.
©<?php echo date('Y', time()); ?>
Try it out! Let us know what you think and if you have a more efficient way of displaying the copyright date please comment below.