PHP code to update the year automatically

0
(0)

This is a set-and-forget line of PHP code that updates the year automatically.

If you forget to update the year in your site’s copyright line, this code will help you update the current year.

<!-- Let's assume this year is 2020, then the code will be as below: -->
Copyright &amp;copy; 2020 <?php if(($y=date("Y")) != 2020) echo "- $y"; ?>

The code date("Y") reads the server’s current date and stores it in the memory with a variable $y and != 2020 checks if the current date is NOT equal to 2020. If it’s not equal, then echo "- $y" print the current year.

If this year is 2020, it displays:

Copyright © 2020

If this year is 2021, it displays:

Copyright © 2020 - 2021
Share this:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *