PDA

View Full Version : Script that calculates age from a given date



kleinline
12-20-2010, 05:01 AM
I am trying to find a script, or help writing a script that displays the age of a business for a yearly anniversary.

For instance, if they opened in 1978, I want to display a statement that says "Celebrating our 32 year anniversary."

It seems like this should be simple, but I am struggling! Any ideas?

:confused:

djr33
12-20-2010, 05:13 AM
How do you want to store the information? Is this a single business or do you want many listings?

It's basic math once it's stored as a variable.

kleinline
12-20-2010, 05:48 AM
It's a single business. I was trying to find a way to display it so that the number would turn over on the exact day, but I must be messing up the math...my script isn't displaying anymore.


var opendate =new Date(2000, 8, 16)
today=new Date()
var one_day=((((Age/1000)/60)/60)/24)/365.25)

//Calculate difference between two dates
document.write("Celebrating our " + (Math.ceil((today.getTime()-opendate.getTime())/(one_day))+
" anniversary!"))

</script>