Avatar ·

How to get the current year in PHP? I'm using date('Y'), but not sure if it's correct

Hello everyone! I'm a beginner in PHP and working on a site for publishing articles. I need to display the current year in the site footer in the format "© 2025 MySite". The problem is that I don't want to manually change the number in the code every year — the site should determine the current year by itself.\n\nI found the date('Y') function on the internet, and it seems to work. Here's my code:\n\n```php\n
\n

© MySite

\n
\n```\n\nBut I doubt whether this is correct. What if the date() function depends on server settings or timezone? Maybe there is a more reliable way? I've also heard about the DateTime class, but I don't understand how to use it for such a simple task.\n\nPlease advise how to professionally get the current year in PHP. Are there any pitfalls or best practices?