logo

Sue Feng Design

‹ Back to blog

Automatic Copyright Year

Are you tired of always having to changing the copyright year to your Web site year after year? Now you don't have to with this PHP snippet. If you already use something like this, that's great. If not, you can learn something new.

If you only want to display the current year you can use this:

© <?php echo date("Y") ?>

If you want a start year as well, you can use this:

© 2011-<?php echo date("Y") ?>

Where 2011 is, that's the start year.

If you just built your site in the start year and you want to have that date stay while the recent year changes after that year is over, you can use something like this:

$start_year = 2011;
if ($start_year == date("Y")) {
     echo $start_year;
}
else {
     echo $start_year."-".date("Y");
}

You put the year you created the site in place of 2011. If the start year is the same as the current year, only the current year is displayed. If the start year is different then it will display like © 2011-2012.

Posted on: June 29, 2012Categories: TutorialsTags: coding, php
‹ Back to blog