An auto updating copyright year

Not so long ago I came across a tweet from John O'Nolan that made me smile because it is so true.

Client facing problems always have a lot more hysteria behind them no matter how small the problem may be. It's something as Front End Developers we become accustomed to dealing with emails and tweets regarding them.

Now, what if we can make some of them a little easier to eradicate by being a little smarter with our implementation. Obviously, time implicates a lot of the smarter things we can develop, but by doing little things here and there, we leave ourselves less perceptible to these small issues that distract from larger issues.

I plan on doing more little snippets on this subject but for this particular post I thought I would just approach the footer copyright year being out of date. No matter how many places I have worked, this is something that always comes up in yearly changes. So here are a few implementations in a few different languages so you can quickly add a fix that will be permanent rather than yearly.

JavaScript

&copy;<span class="js__copyright-year"></span> Michael Tempest
<script>
  var year = new Date().getFullYear();
  document.querySelector('.js__copyright-year').innerHTML = year;
</script>

PHP

&copy;<?=date("Y");?>  Michael Tempest

Rails

&copy;<%= Time.now.year %> Michael Tempest

Comments