Check out this search on this forum: https://community.filemaker.com/search.jspa?q=calculate+age+from+birth
Is it just me, or has this come up a lot lately?
I'm not surprised this comes up frequently. I am surprised that we keep answering it afresh, and with different answers each time, depending on who responds.
For something like this where the outcome is generally agreed upon, it seems that perhaps, in this thread, we should be able to come up with some consensus. We could then point all these threads, and the inevitable future ones, to this thread.
There are, of course, lots of ways to calculate this. Mine might not be (probably isn't) the best. This seems like one of those cases where we all have a different way, they all (well, most of them) work, but there's an opportunity to find a better way. It's not a huge deal, but there's a good chance that most of us could benefit at least a tiny bit by finding the "best" way... or at least just a couple ways with good reasons to pick one or the other.
I did read the post by taylorsharpe about how the Chinese calculate ages differently (good catch!), but for that, we could use the same calc and add a year.
The first and obvious criteria for a "best" way would be that it works with any dates (for example, leap years). After that, I would think it comes down to brevity (just sheer length) and clarity (can we read the darn thing without a bunch of head-scratching?). I wouldn't think performance would be a serious consideration for something this simple, but someone might point out I'm wrong about that.
I'll post my calc, but I'll be shocked if someone else doesn't come up with something shorter and/or clearer. Who knows? Maybe like some of us who've posted to one of these threads, I'll find out my calc doesn't work as well as I thought, and that I've just gotten lucky.
Here's my calc. If someone can do better, I'll be glad to find that out, and I'll switch.
let ( [
beg = getasdate ( "2/29/68" ) // ex: date of birth
; end = getasdate ( "3/1/15" ) // ex: today
; beginDateInEndYear = date ( month ( beg ) ; day ( beg ) ; year ( end ) ) // ex: birthday this year
year ( end )
- year ( beg )
- case (
beginDateInEndYear > end
So... do you have a calc for this that's more accurate, shorter, clearer?