Print Date Using a Script

Friday night Kim Gagliardi retweeted a reminder by Gregory Duval to update your web site copyright for the new year.

This short post is for Gregory and everyone else who doesn’t want to update the copyright on their web site every year. Instead of changing 2011 to 2012 add one of the scripts below to print the date.

PHP

PHP is a server side language, which means your date is pulled from your host server. Using a server side approach to printing the date is best. Please note, that should you choose to print the time from your servers you may realized they are an hour or more off. This is because servers are set to the local time where they physically are, and that may in another timezone.

If you have a WordPress or Drupal blog this code will work for you.

Copyright &copy; <?php echo date("Y") ?>

JavaScript

JavaScript is a client side language, which means your date is pulled from your viewer’s computer. To display properly year the viewer’s computer needs to have the correct year and JavaScript needs to be enabled in the browser.

Copyright &copy; <script type="text/javascript" language="javascript">
document.write(new Date().getFullYear()); </script>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>