Home > Blockchain >  How to code so that the date automatically changes?
How to code so that the date automatically changes?

Time:01-22

How can I modify the following code so the year automatically would change each year?

</div>
</div>
</div></div>
<div >
  <p>Copyright 2023 </p>
  <a href="#" ></a> </div>
</body>
</html>


Meaning I won't need to manually change the Copyright 2023 next year to Copyright 2024.

Thanks a bunch in advance!

I don't know how to make the date modified automatically based on the year.

CodePudding user response:

You need to try the date() function. And maybe your question will be solved.

<div >
    <p>Copyright <?php echo date("Y"); ?> </p>
    <a href="#" ></a> 
</div>

Replace this code and the date() function will dynamically get the current year.

CodePudding user response:

You can use JavaScript to automatically update the year in the copyright statement. For example:

<html>
<head>
  <script>
    document.addEventListener("DOMContentLoaded", function() {
      let currentYear = new Date().getFullYear();
      document.querySelector(".footer p").innerHTML = Copyright ${currentYear};
    });
  </script>
</head>
<body>

  <div >  
    <p>Copyright 2023 </p>  
    <a href="#" ></a> 
  </div>  

</body>  
</html>
  • Related