It's `document.write(new Date().getFullYear());` - Update Your Footer

Published Friday, May 08, 2015

As I was updating some content on my personal website today, I noticed the copyright date in the footer still read “2014”. Yeah, it’s May. Go me.

Sadly, I believe future-me from 2016 would probably make this same mistake, so to help myself out, I did a quick google search for “How to auto update year website”, which yielded this extremely helpful site: UpdateYourFooter.com. It offers JavaScript and PHP solutions, with JS being the easier option for my needs.

Just add the following wherever you want the year displayed:

<script>
  document.write(new Date().getFullYear());
</script>

You can find more info on the JavaScript Date object here. And best of all, this solution is supported in all browsers except IE8. Finally, there’s (of course) a longer discussion about this on StackOverflow, for anyone who wants some additional reading.