/** 起期开始计算年龄(整岁) */
function agesByStartDate(insrntBthd,startDate){
var r = insrntBthd.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null) return false;
var s = startDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(s==null) return false;
var d= new Date(r[1], r[3]-1, r[4]);
if (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]) {
var t= new Date(s[1], s[3]-1, s[4]);
if (t.getFullYear()==s[1]&&(t.getMonth()+1)==s[3]&&t.getDate()==s[4]) {
var arr = new Array();
arr = insrntBthd.split("-");
var startArr = new Array();
startArr = startDate.split("-");
var dYear = t.getFullYear();
var dMonth = t.getMonth()+1;
var dDay = t.getDate();
if((Number(dDay)-Number(arr[2]))<0){
dMonth -= 1;
}
if((Number(dMonth)-Number(arr[1]))<0){
dYear -= 1;
}
return Number(dYear)-Number(arr[0]);
}
}
}
/** 起期开始计算年龄(多少天) */
function agesForDayByStartDate(insrntBthd,startDate) { // 计算出生多少天
var r = insrntBthd.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null) return false;
var s = startDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(s==null) return false;
var nd1 = new Date(insrntBthd.replace(/-/g,"/"));
startDate = new Date(startDate.replace(/-/g,"/"));
var day=startDate.getTime()-nd1.getTime();
day=Math.ceil(day/(1000*60*60*24)); //相差多少天
return day;
}