How to add an automatically updating year to your website

It's 2019, time to update the copyright year for the last time!

The year has changed once again. If you have a static "copyright © 2018" in your website's footer, now it's the time to update it to 2019. Instead of changing the year manually every year, add an automatically updating year to your footer! An incorrect year makes your site look dated and the beginning of the year is the time of change for many, thus a good time for acquiring new customers.

Replace your static year with the following snippets according to the technology you're using:

Javascript

You can use the following in node.js, React, Angular or any other js application.

new Date().getFullYear()

Or, if you're using the fantastic moment.js library:

moment().format('Y')

PHP

If you're using Wordpress, the correct file to edit is most likely "footer.php" in your theme's directory.

<?php echo date("Y"); ?>

Ruby On Rails

Add this to your footer template:

<%= Date.today.year %>

Django

Add this to your footer template:

{% now 'Y' %}

Standard Python

If you're using some other method with Python:

from datetime import datetime
datetime.now().year

ASP.NET

<%: DateTime.Now.Year %>

Static HTML website

If your website is plain static HTML, you can use the following snippet in the place you want. Note that the year will be according to the visitor's time and doesn't work if the visitor has disabled JavaScript.

<script type="text/javascript">
  document.write(new Date().getFullYear());
</script>

Find errors on your website

Sitebot's objective is to keep world's website working with less errors. Read more and start your free trial!