My date of birth is 18 .03.2000 Saturday time 7.30 PM my question is How to calculate my exact age from date my birth.? What is my exact age 19 or 20?
Asked
Active
Viewed 320 times
-3
-
The exact same question is answered [here](https://stackoverflow.com/questions/4060004/calculate-age-given-the-birth-date-in-the-format-yyyymmdd). – Epic Martijn Jul 28 '20 at 09:35
-
Does this answer your question? [javascript - Age calculation](https://stackoverflow.com/questions/4076321/javascript-age-calculation) – Alexandre ELIOT Jul 28 '20 at 09:36
-
To calculate your _exact_ age, you need to know where on the planet you were at time of birth, relative to the current timezone, too :) – Jonathan Hall Jul 28 '20 at 09:36
-
i think it's duplicate see: https://stackoverflow.com/questions/4060004/calculate-age-given-the-birth-date-in-the-format-yyyymmdd – Seif Jul 28 '20 at 09:44
2 Answers
0
You can get a timestamp from your date of birth and substract it from current timestamp which will give you number of milliseconds in your age. You can then convert it into years, days, months, etc.
// Year when you're born
const birthTimestamp = (new Date('03/18/2000')).getTime();
// Current timestamp
const currTimestamp = Date.now();
// Number of milliseconds in your age
const ageMilliseconds = currTimestamp - birthTimestamp;
// Convert this value to years ...

Dharman
- 30,962
- 25
- 85
- 135

Sachin Singh
- 898
- 1
- 8
- 17
-
-
Because I have born on 2000 to 2001 I will be 0 year old on 18.03.2001 I will be 1 year old that months 12 months I will 0 years old how I add my date of birth as 2000 because 2000 do not have any value from 2001 only age starts I should consider my date of birth of year as 2001 18.03.2001 I should consider my date of birth because I can take 2000 as my date of birth because on that year only I have born how I can 1 year old when I born that day in this who ever born can be 1 year old when they born on that day I have subtract 2001-2020 the answer give me I am 19 years old this my formula – L. Aravind Kalaimani Jul 28 '20 at 09:51
-
Age is the time you have elapsed since you were born. If you were born on 18th March 2000, on March 18, 2001 you have elapsed 365 days which is equivalent to an year which makes you 1 year old on March 18, 2001. – Sachin Singh Jul 28 '20 at 10:04
-
-
Not exactly, subtracting year of birth from current year might not always be correct. For example, if you were born in December 2001, You're still 18 years of age. 2020 - 2001 gives you 19 which is incorrect. – Sachin Singh Jul 28 '20 at 10:08
-1
You can use moment.js
and don't worry about calculation! :)
let birthDate = moment('2000-03-18');
let age = moment().diff(birthDate, 'years');
console.log(age);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>

Vahid Alimohamadi
- 4,900
- 2
- 22
- 37
-
-
@MarkusZeller So you can reply him/her and show how to calculate! – Vahid Alimohamadi Jul 28 '20 at 11:45
-
-
-
What do you want to say with that? It is already explained [here](https://stackoverflow.com/questions/4060004/calculate-age-given-the-birth-date-in-the-format-yyyymmdd). – Markus Zeller Jul 28 '20 at 11:50