If you forget to update the year in your site’s copyright line, this code will help you update the current year. This is a set-and-forget line of PHP code to updating the year automatically.
<!-- Let's assume this year is 2020, then the code will be as below: --> Copyright &copy; 2020 <?php if(($y=date("Y")) != 2020) echo "- $y"; ?>
reads the server’s current date and store in the memory with a variable
checks if the current date is NOT equal to 2020. If it’s not equal, then
print the current year.
echo "- $y"
If this year is 2020, it displays:
Copyright © 2020
If this year is 2021, it displays:
Copyright © 2020 - 2021