How to Automatically Update the Year in your Footer Copyright Area

This is definitely one of my favorite javascript hacks, tweaks, uses of 2013.

I am a huge fan of having the copyright year in the footer of any website I build. Since I work with so many different languages, I am not able to always use my go to php “echo date/year” lol. With that said, this little javascript trick works every time on every server, without fail!

Step 1:¬†Create the “date.js” file

function DateYear() {
var d = new Date();
var x = document.getElementById(“DateYear”);
x.innerHTML=d.getFullYear();
}
window.onload = DateYear;

Step 2: Update your html

Copyright &copy;&nbsp;<span id=”DateYear”></span>&nbsp;YourWebsite.com

Step 3: Add the JS file to your HTML document head

<script src=”js/date.js” type=”text/javascript”></script>

Enjoy!

Was this blog post helpful for you?

Support my blog and donate!

My blog is open to the public and will always be freely available. With your donation, we can help others learn, together.