Skip to content

Instantly share code, notes, and snippets.

@WallaceKelly
Last active August 18, 2017 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WallaceKelly/a6a43e779feef431c828304e71633858 to your computer and use it in GitHub Desktop.
Save WallaceKelly/a6a43e779feef431c828304e71633858 to your computer and use it in GitHub Desktop.
Testing a code snippet found on StackOverflow that was offered for calculating the number of years since a given date
// https://stackoverflow.com/a/34642138/167920
function getAge(dateOfBirth, tillDate) {
return (new Date(tillDate).getUTCFullYear() - new Date(dateOfBirth).getUTCFullYear());
}
console.log(getAge('1/2/2000', '1/1/2016'));
// Expected output: 15
// Actual output: 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment