How to Get the Current Year using PHP?
Use the built-in date() function with the format character Y. It gives the current year with 4 digits.
<?php
echo date("Y");
?>
Output:
Output in the year 2026
2026
The most common use is the copyright line in the footer, so you do not have to change it every year.
<footer>
© <?php echo date("Y"); ?> Tutorials Class
</footer>
The year comes from the server time and its time zone. Near midnight of 31 December it can be different for some visitors, see how to change the time zone. The same with the DateTime class: (new DateTime())->format("Y"). More in PHP Date and Time.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Date and Time |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| How to Change Time Zone Settings in PHP? |
| How to Get the Current Year using PHP? |