Skip to content

Instantly share code, notes, and snippets.

@arozwalak
Last active March 9, 2017 22:08
Show Gist options
  • Save arozwalak/7369923 to your computer and use it in GitHub Desktop.
Save arozwalak/7369923 to your computer and use it in GitHub Desktop.
Javascript: check apriopriate birth date
var checkBirthDate = function(month, year, minAge){
var currentDate = new Date();
var bDate = new Date(parseInt(year)+parseInt(minAge), month);
var cDate = new Date(parseInt(currentDate.getFullYear()), parseInt(currentDate.getMonth())+1);
if(bDate.getTime() < cDate.getTime()) {
return true; }
else {
return false; }
}
console.log(checkBirthDate(10, 1995, 18));
var checkBirthDate = function(month, year, minAge){
var currentDate = new Date();
return ((new Date(parseInt(year)+parseInt(minAge), month)).getTime() < (new Date(parseInt(currentDate.getFullYear()), parseInt(currentDate.getMonth())+1)).getTime()) ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment