How to check DOB less then 18 in Javascript


Javascript Function :


 var currDate =01/03/2023

var date_birth = 04/03/1994

function isLessThan18(currDate, date_birth)

{

var currday=parseInt(currDate.substring(0,2),10);

var currMnth=parseInt(currDate.substring(3,5),10);

var currYear=parseInt(currDate.substring(6,10),10);

var dobDay=parseInt(date_birth.substring(0,2),10);

var dobMon=parseInt(date_birth.substring(3,5),10);

var dobYear=parseInt(date_birth.substring(6,10),10);

if(currYear-dobYear<18)

{

return true;

}

else if(currYear-dobYear>18)

{

return false;

}

else if(currYear-dobYear==18)

{

if(currMnth>dobMon)

{

return false;

}

else if(currMnth<dobMon)

{

return true;

}

else if(currMnth==dobMon)

{

if(currday<dobDay)

{

return true;

}

else if(currday>=dobDay)

{

return false;

}

}

}

}




No comments:

Post a Comment

CPU vs GPU Architecture

  CPU vs GPU Architecture CPU (Central Processing Unit) and GPU (Graphics Processing Unit) have distinct architectural differences, optimize...

Best for you