Is there a way to calculate a users age based on their Date of Birth (DOB)?
So my app is a habit tracker and based on the user’s age they will be able to select different habits to track. I’m asking users to input their DOB on registration and ideally I don’t want to then have to ask them to input their age as this will cause issues when their birthday comes up and they are a different age.
Ideally, I would like to calculate their age based on DOB and store this in the user table. Then my UI would display different habits based on their user age e.g. 13-16, 16+.
I’ve searched through the documentation and the support forum but can’t find anything related to this.
My app ID is: C209BEBE-88E7-1122-FF98-41304F96CA00
Thanks for this Vlad. I’ll check it out and let you know how it get on.
@vladimir-upirov is there a way to do this in codeless instead of using code?
Btw, I’ve created an internal ticket to add a function
curyear() to replace the
2020 value, the ticket’s number is BKNDLSS-23658
I’ve set this up and got the 200 success code. But it didn’t save in the age column of the user’s table. I think I need this to save in the user’s table so my frontend app (Appgyver) can read this to display the correct content for that user.
Apologies for all the questions but i’m a rookie at this coding stuff
actually, you do not need to save the property, you can create a
generated column and you will always get the
age property automatically
This is awesome Vlad. I’ve got it working first time.
The generated columns feature may also answer a future question I would have had too.
Many thanks for you prompt help with this,
My pleasure, I’m glad it works for you!
Hello, Vladimir! I’m trying to do the same thing in a generated column. And I’m curious if it’s possible to make more accurate value (not only full years but months as well)?
I tried (and failed) to transform my formula from Airtable platform that shows an age in a “years.months” format. Do any equivalents of rounding formulas exist in Backendless?
My original formula is:
CONCATENATE(ROUNDDOWN((DATETIME_DIFF(TODAY(),DOB, ‘months’)/12), 0))&"."&((DATETIME_DIFF(TODAY(),DOB, ‘months’))-(DATETIME_DIFF(TODAY(),DOB, ‘years’))*12)
DOB: August 18, 1995
Also, I didn’t get how to use this ticket’s number thing in a ‘2021 - year()DOB’ formula If a year is replaced by “curyear()”, the column doesn’t recognize the function.
You would not be able to use the
TODAY() function in a generated column. The system doesn’t allow non-deterministic functions. Here’s a definition of a deterministic function:
A function is deterministic if, given the same data in tables, multiple invocations produce the same result, independently of the connected user
A workaround is to use a formula to request a dynamic property. For example, consider the following scenario - a table contains the
I can request a “dynamic property” with the following formula:
This is the result I get:
To use in the data retrieval API for the
Users table, it will look as follows in the REST request:
Hope this helps.
Thank you very much for the response, it provided food for thought
I’ve been thinking if this “age” value can’t be dynamic in a data table I can use some tools in a UI builder to generate and show it.
I created this form with a date and a read-only block which should calculate an age.
But I got lost in a Value Logic
of the second field. (No matter what’s inside, I just can’t display it)
I’m pretty sure that the result needs to be returned
but it’s not possible with IF statement as I can see.
Could you give me a hint of what I’m doing wrong?
Thank you in advance!
You can return value in the if statement:
If value logic hasn’t return, value of the component always will be empty.
Little tip - use Content Logic at Text components instead of Value Logic of readonly Input
Hi, Dima! Thank you for your advice. I switched from Input to Text and added a return. I should have known that I needed to GET that property
Now everything works and I’m completely happy!
Maybe someone will find this logic useful.