Age from Date of Birth using JQuery

后端 未结 7 1669
轮回少年
轮回少年 2020-11-30 06:42

I need to calculate if someone is over 18 from their date of birth using JQuery.

var curr = new Date();
curr.setFullYear(curr.getFullYear() - 18);

var dob =         


        
7条回答
  •  暖寄归人
    2020-11-30 07:16

    You could use the Date object. This will return the milliseconds between the two dates. There are 31556952000 milliseconds in a year.

    function dateDiff(var now, var dob)
    {
        return now.getTime() - dob.getTime();
    }
    

提交回复
热议问题