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!


Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
epsi profile image
E.R. Nurwijayadi

Wow!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay