$( function() {
    $(
"#datepicker").datepicker({dateFormat: 'mm/dd/yyyy'});
  } );
$("#datepicker").datepicker({
        maxDate:
'+0d',     
        yearRange:
'1914:3025',
       
buttonImageOnly: true,
        changeMonth:
true,
        changeYear:
true,
    }).on('change',
function () {
        var age =
getAge(this);
       
$("#age").html("You are " + age + " old");
    });
    function
getAge(dateVal) {
        var
            birthday =
new Date(dateVal.value),
            today =
new Date(),
           
ageInMilliseconds = new Date(today - birthday),
            years = ageInMilliseconds / (24 * 60 *
60 * 1000 * 365.25 ),
            months =
12 * (years % 1),
            days =
Math.floor(30 * (months % 1));
            return
Math.floor(years) + ' years ' + Math.floor(months) + ' months ' + days + '
days';
    }
No comments:
Post a Comment