Dynamic Copyright Date

The copyright date in a footer of a website is often overlooked, so a site that is updated regularly could still look unloved simply by forgetting to change that date to the current year. This could easily be solved by letting that date change automatically with a small bit of php.

<?php echo date('Y'); ?>

By adding the above code it will generate a 4 digit year automatically

example

&copy; 2009 - <?php echo date('Y'); ?> webdesignpond.co.uk

Alternatively it could be a two digit year by changing the upper-case Y to a lower-case.

&copy; 09 - <?php echo date('y'); ?> webdesignpond.co.uk

For more date formats that can be created using php check out the PHP: date manual

Dynamic First year

Special thanks to Scott from The Web Help Forum for the code below

&copy; <?php ini_set('date.timezone', 'Europe/London');
$startYear = '2009'; $thisYear = date('Y'); if($startYear == $thisYear){ echo $startYear; } else { echo $startYear.' &ndash '.$thisYear; } ?>

This is a more advanced way to set the date, as it will take into account the year the website was created as well as the current year. So if the current year is still the same year that the website is created it will only show that year (e.g 2009), then any year after that it will display it as © 2009 – (current year) (e.g 2009 – 2021).

12
Comments

  • Jen
    May 24, 2010 | Permalink |

    Great tip, this will be useful, thanks Diz

  • May 24, 2010 | Permalink |

    A slightly more advanced version, with (c) Copyright 2008 – CURRENT YEAR can be achieved with


    ©  YOUR NAME

  • May 24, 2010 | Permalink |

    lol oops. It’s stripped out the code!

    It’s available over at the forum anyway :)

    http://www.webhelpforum.co.uk/server-side-snippets/auto-update-copyright-notice/

  • Dizi
    May 24, 2010 | Permalink |

    Thanks for the link Scott :)

    to add code in a comment you need to use [code] …which I haven’t thought to style for comments, so I will have to do that when I get home tonight :p

  • May 24, 2010 | Permalink |

    Ah… I was using the <code> element lol

  • car
    May 24, 2010 | Permalink |

    What makes the code provided in Scotts link better than the code referenced by Dizi?

  • Dizi
    May 24, 2010 | Permalink |

    Scotts code makes the first year dynamic as well. So if the site started in 2009 all through 2009 it will just show © 2009 but then in 2010 and onwards it will show © 2009 – (current year).

  • Dizi
    May 24, 2010 | Permalink |

    There we go added it to the main post with a link to the forum, that way it is explained why it is better and gives credit :-D

  • May 25, 2010 | Permalink |

    I’m always surprised at how many websites/developers don’t do this,
    its such a simple step that goes a long way to building a visitors confidence in a site, its crazy not to do it!

  • Dizi
    May 25, 2010 | Permalink |

    Yup I agree Gavin, a common argument that I have read is that its not that difficult to change the date once a year, but if you do a site for someone else or manage a lot of sites, surely it is easier to do this and then not have to worry about changing the date on all the sites each year.

    And as you have said it does give visitors a sense of confidence in the site.

  • July 2, 2010 | Permalink |

    Just noticed you’d included it in the main post pixie. Nicely done :)

    (In fairness, I only noticed cos I’ve had about 3 dozen hits from this page in the past couple of weeks lol)

    Keep up the good work pixie :)

  • August 24, 2010 | Permalink |

    Thanks Scott and Dizi I will be using this on all my sites it saves me remembering to change it every year

Have Your Say

Your email is never shared. Required fields are marked *
To add code to a comment use this [code] your code here [/code]