// JS date series: Get age of age by date of birth
// The strbirthday parameter is already a date string in the correct format such as 2007.02.09
// Add related JS methods for date processing, such as date judgment, to be added later
Function jsgetage (strbirthday)
{
VaR returnage;
VaR strbirthdayarr = strbirthday. Split (".");
VaR birthyear = strbirthdayarr [0];
VaR birthmonth = strbirthdayarr [1];
VaR Birthday = strbirthdayarr [2];
D = new date ();
VaR nowyear = D. getyear ();
VaR nowmonth = D. getmonth () + 1;
VaR nowday = D. getdate ();
If (nowyear = birthyear)
{
Returnage = 0; // The same year is 0 years old
}
Else
{
VaR agediff = nowyear-birthyear; // year difference
If (agediff> 0)
{
If (nowmonth = birthmonth)
{
VaR daydiff = nowday-birthday; // day difference
If (daydiff <0)
{
Returnage = agediff-1;
}
Else
{
Returnage = agediff;
}
}
Else
{
VaR monthdiff = nowmonth-birthmonth; // The difference between months
If (monthdiff <0)
{
Returnage = agediff-1;
}
Else
{
Returnage = agediff;
}
}
}
Else
{
Returnage =-1; // return-1 indicates that the input date of birth is later than today
}
}
Return returnage; // return age
}