PDA

View Full Version : Automated copyright code


RexxCrow
05-10-2008, 06:36 AM
I was just tooling around for a way to make my pages auto update their years and put this little script together, thought it was pretty helpful so I figured I should post it. Originally I made this thinking that copyrights expired either 7 or 14 years, but after looking it up it actually looks like in the USA at the minimun they last 95 years and at the most it is 120 years, but this still works, but I guess it really is not needed though.

Place in head javascript section (change the two "95"'s to what ever time period you need and change c to the actual starting date of the content):
function yearSet(){
c=2007
cd=new Date()
y=cd.getYear()
if(y<1000){
y+=1900
}
test=y-c
if(test>95){
update=(test-95)
c=c+update
}
if(c==y){
gop=y
}else{
gop=c+'-'+y
}
document.getElementById('year').innerHTML=gop
}

Place wherever your copyright stamp is to be displayed:
&copy; Copyright <span id="year"></span>

place at very end above the "/body" tag (or you can make this into a onload function)
<script language="javascript"><!--
yearSet()
//--></script>


Or if you rather just want a simple verision:

Place in head javascript section:
cd=new Date()
y=cd.getYear()
if(y<1000){
y+=1900
}

Place wherever your copyright stamp is to be displayed (change the 2007 to what ever year needed, though if it is for the same year this will not work correctly because it will show the same year twice unless you remove the static hardcode, in which case next year you will need to put it back so this will make you work a little harded the other more complex code above does this for you):
&copy; Copyright 2007-<script language="javascript"><!--
document.write(y)
//--></script>

Minkey
05-26-2008, 08:20 PM
Useful script. Something to remember to do when you are building a site. It is a hassle having to go back to lots of websites in January each year and update the copyright date!

Here's a thought... add it to your checklist of things to do when you build your website :)

thecodemeist3r
06-17-2008, 04:37 AM
A really good script.

shamess
06-26-2008, 07:57 PM
Just so you guys know, you don't have to update the year in the copyright notices - you don't even need a copyright notice. Most countries have intellectual property laws making it so you have copyright of your works for 70 years at least after the day you die.

fside
06-27-2008, 04:51 AM
you have copyright of your works for 70 years at least after the day you die

I suspect I would care less about it, three quarters of a century after I'm buried in the ground. Somebody may benefit - but it won't the "you" in "your works".