Copyright Year In Website


As the new year started and most of the websites are having a statement stating the copyright © [year].
Here is the year which is currently running and this should be 2023 as of today's date so the statement becomes copyright © 2023 starting from 1st January and in the last year it is copyright © 2022 

So each year this needs to be updated if this is statically defined and we generally make this static in the initial days of the website development and later we forget to change this, Even you people see many times the wrong year in the footer for many other websites. This is just that this is statically defined.

So today I'm giving you a short code or trick by which the year changes automatically with each passing year.

Let me show you an example by taking a C# corner footer itself, below is the footer of the C# corner website. Here you can see the year at the end of the footer.

So let's take an example of how this can be dynamically generated

HTML Code (index.html)

<div id="footer">
        <p>Copyright &copy
            <span id="year"></span>
            C# Corner Blogs

JS Code (script.js)

 const year= document.getElementById("year");
 const currentYear=new Date().getFullYear();

Pro Tip - you can use &copy Unicode to create a copyright symbol while mentioning the copyright year in the footer of the website.



So this is the simple code that you can use anywhere on the website where you need to define the running year and your website end user did not see the last year or the wrong year in the footer of website.

Anyway Happy New Year to you all and Happy Coding :)