Forum Academy Marketplace Showcase Pricing Features

How calculate user age

First off, I didn’t mean to disparage your response, and apologize if that’s how you interpreted it. My intention was to acknowledge that your response actually does work in edge cases, and to provide an alternative for those who don’t want to rely on external sources which we don’t have control over.

In regards to the code not working, I was able to test it out just now in an internal app, and it seems to work fine on my end. I’d love to share a link to an editor to demonstrate this, but unfortunately backend workflows require a paid plan.

If you let me know what issue you’re having, I’d be happy to help you debug it. Your use case of months should be possible with slight modifications.

I’m also working on a plugin which will have a number of useful datetime-related utilities including get age, so I can update this thread when I’ve finished it.

I posted that in 2018 and never really expected anyone to use the function. Am amazed it is still working even though webtask had been discontinued.

Suspect the issue is with the format of what is being passed in.

MM/DD/YY as a format as ? Are you sure ?

I will answer my own question …

“formatted as MM/DD/YY” looks like it wants to be a Custom format (MM/DD/YY) which doesn’t work). My fault for overcomplicating it.

But actually, you want YYYY because people are living to 100 now :slight_smile:

So…Just pick the 2nd on the list.

Anyway, months in my case was as simple as the difference between the two dates in days / 31 as it just needs to be approx.

1 Like

Actually, you (simply) need to do what you do in real life:

  • you look at the year of birth and make the difference with the current year
  • then you check whether the current day of the year is higher than the birth day of the year, and decide to subtract 1 or not

Here is the formula (i’m using a date / time picker):


Hope it helps someone! :slight_smile:

There’s an easy way:

“Current time:extract date >= BIRTHDAY:extract date:formatted as text”
if yes → Current time:extract year - BIRTHDAY:extract year
if not → Current time:extract year - BIRTHDAY:extract year - 1

if you need as number, convert it as number later

1 Like

I have found a way which is intuitive and easy to write in native bubble. It handles leap years perfectly as far as I can tell.

  1. subtract DOB year from this year
  2. if current date in DOB’s year is before DOB, subtract 1, otherwise subtract 0


More details:

And it works in the back end too.