DEV Community

Cover image for Dynamic Copyright Date
nightwolfdev
nightwolfdev

Posted on • Edited 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!

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more