Aimalou
I realize this response comes a year late. My daughter was born earlier this month and I felt the need for a similar script. I worked on it until I was satisfied with it. I think it's what you are looking for.
I wrote a function which says a persons age in english just like I would say it if I was asked. I mean for example if a kid is born on Feb 1st 2002, and today is September 25th 2005 that kid is 3 years, 7 months and 24 days old, but who in the world says that?? "My kid is 3 years 7 months and 24 days old"!?? No, I would probably say "My kis is 3 and 1/2 years old". Thats what my script does.
It tries to show the relavent detail in the age wether its few days, few weeks, few months, or few years it describes it appropriately.
The kid is "3 days old"
or "3 weeks and 1 day old"
or "4 1/2 months"
or "16 months"
or "2 years"
etc..
The code is split into two part, the javascript function getAge(birth) which takes the birth date as a parameter and then the HTML code where you tell it the birth date.
In this example I am using an arbitrary example for birth date January 1st 2000. You can change that to whenever your grandchild was born.
<HTML>
<head>
<script type="text/javascript">
<!--
function getAge(birth)
{
var now = new Date();
aSecond = 1000;
aMinute = aSecond 60;
aHour = aMinute 60;
aDay = aHour 24;
aWeek = aDay 7;
aMonth = aDay * 30;
var age = now.getTime() - birth.getTime();
if (age < 0) {
return "not born yet"
}
years = (new Date(now.getTime() - aMonth (birth.getMonth()) )).getYear()
- (new Date(birth.getTime() - aMonth (birth.getMonth()) )).getYear();
offsetNow = (new Date(now.getTime() - aDay (birth.getDate() -1) ));
offsetBirth = (new Date(birth.getTime() - aDay (birth.getDate() -1) ));
if(years > 1){
months = years12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}else{
months = (now.getYear() - birth.getYear())12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}
agestr="";
if (months < 24){
weeks = Math.floor(age / aWeek);
age -= weeks * aWeek;
days = Math.floor(age / aDay);
if(weeks > 0){
if(weeks == 1){
agestr = agestr + weeks + " week ";
}else if(weeks < 9){
agestr = agestr + weeks + " weeks ";
}else{
agestr = agestr + months ;
if(now.getDate() - birth.getDate() > 10){
agestr = agestr + " ½ ";
}
agestr = agestr + " months ";
}
}
if(days > 0){
if(weeks < 9){
if(weeks > 0){
agestr = agestr + " and ";
}
if(days == 1){
agestr = agestr + days + " day ";
}else{
agestr = agestr + days + " days ";
}
}
}
}else{
agestr = agestr + years;
if (months%12 > 5 && years<14){
agestr = agestr + " ½ ";
}
agestr = agestr + " years ";
}
return agestr;
}
// -->
</script>
</head>
<BODY>
<BR>
<BR>
<BR>
<CENTER>
<BR>
<script type="text/javascript">
document.write("<font size=6> I am " + getAge(new Date("January 1, 2000 ")) + " old</font>");
</script>
</CENTER>
</body>
</html>