Skip to main content

Posts

Better auto updating copyright date

At the start of every year, there always seem to be several blog posts about how to automatically update the copyright date in the footer of your site. These all seem to rely on using the date function in PHP to output the current year. Although this works fine in most cases, it falls apart if in the first year you want it to say just 2012, but next year you want it to say 2012-2013 instead of just 2013. If we wrap this logic up in a function, it will be able to automatically display either just the single, current year, or a range from set year to the current one. Below is such a code snippet and examples of how to use it. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 /**   * Return the given copyright string, with an auto updating year   * Will either return the single, current year, or a range if a start is supplied that's not the current year   *   * Examples:   *