Skip to content

Instantly share code, notes, and snippets.

@chrisenytc
Last active August 29, 2015 14:04
Show Gist options
  • Save chrisenytc/212b56509e1776e29766 to your computer and use it in GitHub Desktop.
Save chrisenytc/212b56509e1776e29766 to your computer and use it in GitHub Desktop.
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