This article was published on December 29, 2010

New Year’s Resolutions: Dynamically Update your Copyright Notices (includes all code samples)


New Year’s Resolutions: Dynamically Update your Copyright Notices (includes all code samples)

happy_new_yearOnly a couple of days left until we celebrate the new year. Champagne, parties, fireworks and yes, new years resolutions.

One thing that is on a lot of web professionals todo lists is to update their ‘Copyright’ notices. Or at least it should be.

A lot of websites take hours, days or even years to update. Google generally takes up to 48 hours to update all their footers but it is not unlikely to find “Copyright 2006” on some websites even today.

So why not automate the whole thing like we did for our blog? A few lines of code are enough to just print the year there. As long as your server’s internal clock is on time you will always display the current year.

The <3 of EU tech

The latest rumblings from the EU tech scene, a story from our wise ol' founder Boris, and some questionable AI art. It's free, every week, in your inbox. Sign up now!

Since you are going into code anyway you might as well change that “2010” to one of the dynamic code snippets below and you will be forever up-to-date:

PHP:
<?php print date("Y"); ?>

ASP:
<%response.write("Current Year: "&Year(Date))%>

ASP.NET:
<%Response.Write(System.DateTime.Now.Year.ToString());%>

Javascript:
<script type="text/javascript">
<!--
document.write(new Date().getFullYear())
//-->
</script>

Ruby:
Date.today.year

Java
import java.util.*;
import java.text.*;

public class Apollo {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat simpleDateformat=new SimpleDateFormat("yyyy");
System.out.println(simpleDateformat.format(date));
}
}

Unix Shell
date +%Y
Go (golang)
package main
import ("fmt"
"time")
func main() {
var t = time.LocalTime()
fmt.Println(t.Year)
}

Python
from datetime import date
print date.today().year

x86 Assembly
jmp start
year db "0000$"
start:
mov ah, 04h
int 1Ah

mov bh, ch
shr bh,4
add bh,30h
mov [year], bh
mov bh,ch
and bh,0fh
add bh,30h
mov [year+1],bh

mov bh, cl
shr bh,4
add bh,30h
mov [year+2], bh
mov bh,cl
and bh,0fh
add bh,30h
mov [year+3],bh

mov ah,09h
mov dx, offset year
int 21h

mov ah,4Ch
mov al,00
int 21h

Lua
print(os.date("*t").year)

Clojure
(let [date (java.util.Date.)
sdf (java.text.SimpleDateFormat. "yyyy")]
(println (.format sdf date)))

Objective-C
#import
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"%d", [[NSCalendarDate date] yearOfCommonEra]);
[pool drain];
return 0;
}

Tcl
set year [clock format [clock seconds] -format {%Y}]
puts $year

Delphi
ShowMessage( IntToStr(YearOf(Now)) );

Haskell
import System.Time
main = getClockTime >>= toCalendarTime >>= print . ctYear

Any other code snippets that are useful?
Let me know in the comments so I can add them.

@redfeet: @Boris Asp.Net: <%=Now.Year.toString%> Classic ASP: <%=Year(Date())%>
all the best for the 10

Get the TNW newsletter

Get the most important tech news in your inbox each week.

Published
Back to top