Skip to content

Instantly share code, notes, and snippets.

@rodrigodiasnoronha
Last active January 15, 2023 02:00
Show Gist options
  • Select an option

  • Save rodrigodiasnoronha/d5a7d38b757d4db7ee9e5d5d3dae47e6 to your computer and use it in GitHub Desktop.

Select an option

Save rodrigodiasnoronha/d5a7d38b757d4db7ee9e5d5d3dae47e6 to your computer and use it in GitHub Desktop.
Pegar a idade de uma pessoa pela data
export const getAge = (dateString) => {
var today = new Date();
var birthDate = new Date(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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment