This comment has been removed by the author.
test
var dob = $('.txtBabyBirthDate').val().split("/"); var fromdate = new Date(dob[2], dob[1] - 1, dob[0]); var todate1Sep = new Date("2019-09-01"); age = [], y = [todate1Sep.getFullYear(), fromdate.getFullYear()], ydiff = y[0] - y[1], m = [todate1Sep.getMonth(), fromdate.getMonth()], mdiff = m[0] - m[1], d = [todate1Sep.getDate(), fromdate.getDate()], ddiff = d[0] - d[1]; if (mdiff < 0 || (mdiff === 0 && ddiff < 0))--ydiff; if (mdiff < 0) mdiff += 12; if (ddiff < 0) { fromdate.setMonth(m[1] + 1, 0); ddiff = fromdate.getDate() - d[1] + d[0]; --mdiff; } //השמת ערך בשדה נסתר גיל --ההשמה לתוך מערך גיל if (ydiff > 0) age.push(' שנים:: ' + ydiff);//+ (ydiff > 1 ? 's ' : ' ') if (mdiff > 0) age.push(' חודשים:: ' + mdiff);//+ (mdiff > 1 ? 's' : '') if (ddiff > 0) age.push(' ימים:: ' + ddiff);//+ (ydiff > 1 ? 's ' : ' ') $(".BabyAge1SepValue").val(age.join(''));
This comment has been removed by the author.
ReplyDeletetest
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletevar dob = $('.txtBabyBirthDate').val().split("/");
ReplyDeletevar fromdate = new Date(dob[2], dob[1] - 1, dob[0]);
var todate1Sep = new Date("2019-09-01");
age = [],
y = [todate1Sep.getFullYear(), fromdate.getFullYear()],
ydiff = y[0] - y[1],
m = [todate1Sep.getMonth(), fromdate.getMonth()],
mdiff = m[0] - m[1],
d = [todate1Sep.getDate(), fromdate.getDate()],
ddiff = d[0] - d[1];
if (mdiff < 0 || (mdiff === 0 && ddiff < 0))--ydiff;
if (mdiff < 0) mdiff += 12;
if (ddiff < 0) {
fromdate.setMonth(m[1] + 1, 0);
ddiff = fromdate.getDate() - d[1] + d[0];
--mdiff;
}
//השמת ערך בשדה נסתר גיל --ההשמה לתוך מערך גיל
if (ydiff > 0) age.push(' שנים:: ' + ydiff);//+ (ydiff > 1 ? 's ' : ' ')
if (mdiff > 0) age.push(' חודשים:: ' + mdiff);//+ (mdiff > 1 ? 's' : '')
if (ddiff > 0) age.push(' ימים:: ' + ddiff);//+ (ydiff > 1 ? 's ' : ' ')
$(".BabyAge1SepValue").val(age.join(''));