DEV Community

Discussion on: Which one is the better function for calculating age?

Collapse
 
fnh profile image
Fabian Holzer

The both functions return the age after the birthday has passed, regardless whether it has actually passed or not. So unless a person is born on first of january, the implementations return a incorrect result for some part of the current year.

Collapse
 
dipotanchangya profile image
dipotanchangya

Thank you for pointing that out. I wanted to keep it simple and just get the age, but it turns out it's not accurate. Could you recommend a better function, one that returns YY-MM-DD-HH-SS?