DEV Community

Cover image for Dynamic Copyright Date
nightwolfdev
nightwolfdev

Posted on • Updated on • Originally published at nightwolf.dev

Dynamic Copyright Date

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();
Enter fullscreen mode Exit fullscreen mode

The date object provides a method called getFullYear. We can use that to get the current 4 digit year.

var year = date.getFullYear();
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

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');
Enter fullscreen mode Exit fullscreen mode

Helpful Resources


Visit our website at https://nightwolf.dev and follow us on Facebook and Twitter!


Top comments (1)

Collapse
 
epsi profile image
E.R. Nurwijayadi

Wow!