Use PHP/JavaScript to get the current year

JordanTBH Knowledgebase / Browse the free Knowledgebase provided by JordanTBH Technologies.

Fancy displaying the current year and avoid having to update your copyright every year? It's really simple.

PHP Methods
<?php echo date("Y"); ?>
<?= date('Y') ?> (This requires PHP 5.4+)
© <?php echo date("Y"); ?> - All rights reserved.
© <?php $copyYear = 2013; $curYear = date('Y'); echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : ''); ?> My Company.

JavaScript Method
View the JavaScript method

Additional Notes
  1. We recommended the PHP method over the JavaScript method.

This article applies to the following:
  • PHP: Hypertext Preprocessor - Server-side HTML embedded scripting language. It provides web developers with a full suite of tools for building dynamic websites: native APIs to Apache.
  • JavaScript Kit- Your comprehensive JavaScript - JavaScript (JS) is a dynamic computer programming language. It is most commonly used as part of web browsers, whose implementations allow client-side

Is this article outdated? Please let us know →
Updated 18/01/14 @ 08:55 PM Daniel D, Editor