Last active
August 29, 2015 14:04
-
-
Save chrisenytc/212b56509e1776e29766 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseAge(dateString) { | |
function parse(date) { | |
date = date || '00/00/0000'; | |
var dateStorage = date.split('/'); | |
return dateStorage[1].replace(/^0/, '') + '/' + dateStorage[0] + '/' + dateStorage[2]; | |
} | |
var today = new Date(); | |
var birthDate = new Date(parse(dateString)); | |
var age = today.getFullYear() - birthDate.getFullYear(); | |
var m = today.getMonth() - birthDate.getMonth(); | |
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { | |
age--; | |
} | |
return age; | |
}; | |
if (parseAge('17/06/1993') >= 18) { | |
return true; | |
} else { | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment