Having the correct current year in the footer of your website is a handy thing if you don't wish to keep manually updating it. Heres how you can have it automatically update without the needs of manual code editing.
Auto date current year
echo date("Y");
Auto date with start year
© 2008- echo date("Y");
Start date with error protection
function autoCopyright($year = 'auto'){
if (intval($year) == 'auto'){
$year = date('Y');
} elseif (intval($year) == ('Y')){
echo intval($year);
} elseif (intval($year) < ('Y')){
echo intval($year);
} else {
echo date('Y');
}
Usage
autoCopyright(); //2019
autoCopyright("2010"); // 2010 - 2019
Reader's Comments