How To Display Current Year in PHP

By Angsuman Chakraborty, Gaea News Network
Saturday, March 1, 2008

The most common use of this is to display the current year in the copyright message dynamically. Anyone who really knows PHP should be able to do it easily. However not everyone who has to use PHP knows PHP, like, for example, people using snippets in ModX or modifying templates in WordPress. Here is the code snippet for them:
<php echo date('Y') ?>

January 10, 2010: 9:26 am

Thanks. works fine for me.

Moshaver Melk
November 4, 2009: 7:32 pm

thanks for sharing! the code was correct

March 2, 2008: 1:14 pm

You are right that the ending semi-colon is not required but the “?” is required to set off the PHP tag it won’t be parsed and will not appear as the browser will parse it as if it were an unknown HTML element.

March 2, 2008: 3:14 am

The code is correct. Semicolon is not required before ending PHP tag.

March 1, 2008: 12:29 pm

3rd Try is the charm:
<?php date(’Y'); ?>

March 1, 2008: 12:28 pm

Um er… Your comment filter killed my code so here it is:

&lt?php date(’Y'); ?>

March 1, 2008: 12:25 pm

You might have better luck with the following since your PHP tag is incorrect:

will not be displayed