PHP: Display Current Year to Automatically Update Copyright Years

I guess most of the websites out there are using plain strings for the years of footer copyright because many of them are still showing 2009 right now. If you have quite a few websites as I do, it’d be kind of intimidating to manually update the copyright years for all of them. So why not use PHP to output the current year automatically? The code is dead simple:

&copy; Copyright 2006 - <?php echo date('Y'); ?>

The PHP date() function does the job, the format string ‘Y’ tells it to return the current year in 4 digits. Now your website would automatically update the copyright footer year to 2006 – 2011 when comes next year.

While it may seem a good idea without tradeoffs, when you think about it, it does consume a little bit more computing resources to process the pages because it’s a function rather than a plain text string. Without a content cache, the date() function would use up extra 0.000045 seconds upon every page view (tested on my personal computer with WAMP installed on Windows XP SP2, could be larger on virtual host where computing power is restrained). With a site receiving 100,000 page views per month, the users would lost a total of 54 seconds across the year. There are also server computing resources that could otherwise be saved, thus electricity, and thus your website’s carbon footprint.

Up to you, though, especially if your time is valuable enough.

1 thought on “PHP: Display Current Year to Automatically Update Copyright Years”

Comments are closed.

Scroll to Top