Are you tired of changing the copyright date on your website? Instead of changing the date manually every year, you can use a bit of code to automatically display the current year!
Javascript
Let’s start with creating a variable called date to hold the date object.
var date = new Date();
The date object provides a method called getFullYear. We can use that to get the current 4 digit year.
var year = date.getFullYear();
All that’s left now is to output the value somewhere on your page. In the below example, we’re looking for a unique id of copyright and setting its inner html to be the current year.
document.getElementById('copyright').innerHTML(year);
PHP
PHP makes it a little easier because you can pass in the format you’d like and echo the value anywhere you want it to appear on the page.
echo date('Y');
Top comments (1)
Wow!