Copyright date on sites
If you have your site, you probably have a copyright notice at the bottom of every page. Included in this notice is usually a year. Some people indicate the year the content started up to the current year, others just indicate the current year. If you have a notice like this, it's very convenient to just type in the current year. But then when the year changes, you need to update all of your templates (or even worse, all of your pages) to show the new year. Naturally nobody does this on New Year's Eve, so for some period of time your site has the wrong year listed.
There's an easy way around this. Instead of entering the year, put in code that will calculate the current year instead. This way you never need to update your copyright notice as the years roll by.
If you are using PHP with the Smarty templating system, here is an example of how you'd create a copyright notice that changes years automatically:
If you are using PHP but not Smarty, you should be using Smarty :), you can also do this directly in the PHP like so:
In both these cases, we are just getting the current date and then formatting so that only the year is shown. If you are using some other language, there is almost certainly a way in which you can get the current date, and a way to format this date. So while the specifics will vary somewhat, you can still use this approach to create a copyright notice that updates the year automatically.
There's an easy way around this. Instead of entering the year, put in code that will calculate the current year instead. This way you never need to update your copyright notice as the years roll by.
If you are using PHP with the Smarty templating system, here is an example of how you'd create a copyright notice that changes years automatically:
Copyright © 2007 - { $smarty.now|date_format:"%Y" } My Company, Inc.
If you are using PHP but not Smarty, you should be using Smarty :), you can also do this directly in the PHP like so:
Copyright © 2007 - <?php echo date('Y'); ?> My Company, Inc.
In both these cases, we are just getting the current date and then formatting so that only the year is shown. If you are using some other language, there is almost certainly a way in which you can get the current date, and a way to format this date. So while the specifics will vary somewhat, you can still use this approach to create a copyright notice that updates the year automatically.
| Rating: | 100% positive, 1 Vote |
| Categories: | web programming php Smarty |
| Added: | on Mar 11, 2008 at 8:14 am |
| Added By: | an anonymous user |

