tags:

views:

11979

answers:

7

I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be out-of-date. How would I make the year update automatically with PHP4 and PHP5?

+19  A: 
<?php echo date("Y"); ?>
Daniel Papasian
+1  A: 
strftime("%Y");

I love strftime. It's a great function for grabbing/recombining chunks of dates/times.

Plus it respects locale settings which the date function doesn't do.

Mark Biek
+5  A: 

http://us2.php.net/date

echo date('Y');

chrisb
+1  A: 

print date('Y');

For more information, check date() function documentation: http://www.php.net/date

+1  A: 

This one gives you the local time: $year = date('Y'); // 2008

And this one UTC: $year = gmdate('Y'); // 2008

Alisey
+4  A: 

You can use either date or strftime. In this case I'd say it doesn't matter as a year is a year, no matter what (unless there's a locale that formats the year differently?)

On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the php manual on date:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

From this point of view, I think it would be best to use strftime as much as possible, if you even have a remote possibility of having to localize your application. If that's not an issue, pick the one you like best.

Erik van Brakel
+8  A: 
gregmac