iandevlin.com

Icon

A mixture of musings on web design & development, history, and life

Automate your website copyright date

copyright

Now that the new year is here, many of us will forget to change the © copyright date on our many websites. I’ve never really been sure why developers don’t always automate this process and therefore not have to worry about it at the change of the year. In this short post I will show you some quick methods of automating this process.

PHP

If your pages are written in PHP, all you need to do is to add this simple line in the place that you want the date to appear:

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

JavaScript

You can also use this simple JavaScript code to generate the year:

<script type='text/javascript>document.write(new Date().getFullYear());</script>

.NET

The two methods for C# and VB are very similiar, but I’ve included both for completeness.

C#:
<%= DateTime.Now.Year.ToString(); =>

VB:
<%= DateTime.Now.Year.ToString =>

Python

In Python, all you have to do is import the datetime library and add the line:

print datetime.date.today().year

Of course there are other languages and methods of doing this, these are just a few. I will add more as I find them or if others suggest that I should.

If you have any other suggestions of ways to automatically output the year on a webpage, or have other languages to suggest, please do so.

http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/digg_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/reddit_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/delicious_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/technorati_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/google_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/facebook_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/twitter_24.png

Related posts:

  1. Website Optimisation
  2. MySql, PHP, dates and times
  3. HTML5 – more widespread than you think

7 Responses

  1. [...] This post was mentioned on Twitter by Ian Devlin, Michael Davis. Michael Davis said: RT @iandevlin: New blog post: automate your website copyright date: http://bit.ly/5zW0bX #webdesign #webdevelopment [...]

  2. [...] This post was Twitted by iandevlin [...]

  3. Tady Walsh says:

    Good ol’ autodate. Good man. Doesn’t get enough of a mention…

  4. ian says:

    Updated for Python.

  5. Don't forget says:

    [...] I had made a blog post about that very thing! Automate your website copyright date web :: blog :: twitter Reply With Quote   + Reply to Thread [...]

  6. stv says:

    Nice! However, I found a bug. Your PHP example has an incorrect PHP closing tag. Should be ‘?>’.

    I found this when I cut and paste the code for my site.

    stv

  7. ian says:

    Doh, thanks. Fixed!

Leave a Reply