PHP Automatic Copyright Year

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

Share This

Written By

MarkBaker

Mark Baker

Hello, my name is Mark Baker, Im a miserable git that lives in South Wales, UK. I love moaning about anything and everything. My go to pet moans are cyclists and politics. Im left wing and if you dont like it then dont read my stuff #SIMPLES!

Reader's Comments