Auto updating copyright

A short function that helps you keeping the current year in your copyright sentence.

function autoUpdatingCopyright($startYear){
 
    // given start year (e.g. 2004)
    $startYear = intval($startYear);
 
    // current year (e.g. 2007)
    $year = intval(date('Y'));
 
    // is the current year greater than the
    // given start year?
    if ($year > $startYear)
        return $startYear .'-'. $year;
    else
        return $startYear;
}
Snippet Details



print '© ' . autoUpdatingCopyright(2001) . ' Jonas John';
 
/*
Output:
 
(c) 2001-2007 Jonas John
 
*/

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!


Older comments:

Bill March 06, 2010 at 18:59
If you notice, his will output a range of years based on the $startyear parameter.

So autoUpdatingCopyright(2006) would output

2006-2010

Your example just outputs 2010.

A matter of choice as to which you like best I guess... The range is common however...
Some)ne February 18, 2010 at 04:27
Is this not much simpler?!

&copy; 2009 - <?xxx $year = (date('Y')); echo $year;?>

(xxx = php)