3 examples of 'calculate date of birth from age in javascript' in JavaScript

Every line of 'calculate date of birth from age in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
52export function ageAsOf(birthDate, date) {
53 if (!birthDate || !date || !birthDate.isValid() || !date.isValid()) {
54 return null;
55 }
56
57 const onOrAfterBirthday = (
58 date.month() > birthDate.month() || (
59 date.month() === birthDate.month()
60 && date.date() >= birthDate.date()
61 )
62 );
63
64 return (date.year() - birthDate.year() - (onOrAfterBirthday ? 0 : 1));
65}
1function age(birthday) {
2 var ageDifMs = Date.now() - birthday.getTime();
3 var ageDate = new Date(ageDifMs);
4 return Math.abs(ageDate.getUTCFullYear() - 1970);
5}
5public getAge(): number {
6 return moment().diff(moment(this.value), "years");
7}

Related snippets