What Is A Dynamic Footer Year Or Timestamp?
Ever looked at a website and wondered if it is still in operation? Maybe a thing or two looked like they could have been updated – and then you notice the copyright notice the in the footer. “2012. Right, this site must be dead. Let’s move along.”
Of course, it could be that the owner just forgot to update the year in the footer. That happens a lot, especially if those years are hard-coded strings. To future-proof your footer, it’s better to just let computers take care of this. Grab one of these snippets and paste that on your page (or forward this site as a friendly reminder to someone who can do it for you).
This is pure JavaScript, meaning it will refresh the year browser-side, depending on the user’s time settings. Just copy the below snippet and paste it where you want your dynamic text in the footer to appear.
<script type="text/javascript">
document.write(new Date().getFullYear());
</script>
HTML output:
If you want, you can always add more information :
© 2006<script>new Date().getFullYear()> 2006&&document.write("-"+new Date().getFullYear());</script>, Your Company.
HTML output:
Because JavaScript works on the client (the user’s browser, that is), it is dependent on the user’s settings. In most cases it will likely be what you’d expect. Here’s more info on the JavaScript Date Object.
You can even install the Node package ‘rainge’ for having a truly automated way to keep your date stamps updated – you just set the year once, and rainge does the rest.
Here’s the same in PHP so you can do this server-side. Use WordPress? Find the ‘footer.php’ in your Editor and add this there (here are videos to help you with that). The below snippet will just show the current year:
© <?php
$fromYear = 2006;
$thisYear = (int)date('Y');
echo $fromYear . (($fromYear != $thisYear) ? '-' . $thisYear : '');?> Company.
HTML output:
© Your Company.