Simple copyright year function

18 Apr 2009 Ferado

I still see on a lot of sites the copyright date being outdated. Shoot, it was even outdated on mine. How embarrassing. Easy fix though. Something I do at work all the time, but since I’m not getting paid for this site, it wasn’t done.

Now, let’s forget the past and move onto the future.

The solution (in PHP):

[cc lang=”php”]
function copyright_year($year = ‘2009’, $sep = ‘-‘) {
$current_year = date(‘Y’);
return ($year == $current_year) ? $year : $year . $sep . $current_year;
}
[/cc]

OR, for those that need more lines (I do too. I like to be able to READ my code):

[cc lang=”php”]
function copyright_year($year = ‘2009’, $sep = ‘-‘) {

$current_year = date(‘Y’);

// compare year that is passed in with current year
if($year == $current_year) {
return $year;
}

// I hate writing the word “else”
return $year . $sep . $current_year;

}
[/cc]

I’ve also made it easy for you to download the source code, just in case you like things REALLY simple! I do, don’t be shy.

DOWNLOAD SOURCE CODE