Age auto update

I added the age field in my users table and its first update calculated after registration from birthdate. But how do I update this field after users birthday? I can update it after each login, but if user wasn’t online for a long time it will not be updated until he’s logged in. But this approach ruins some functionality of my app which depends on the correct user age. How to trigger the age field update exactly on the user’s birthday without him doing anything in the app?

Hi.
Your case is suitable for using Generated Columns. So the age column become a calculated column, which value will depend on the birth column.
https://backendless.com/docs/rest/data_generated_columns.html

Try the functions:
Use NOW() or NOW(fraction_part) → returns ‘YYYY-MM-DD hh:mm:ss.fraction’
or
UnixTimestamp() or UnixTimestamp(from) → seconds since ‘1970-01-01 00:00:00’ UTC or from the argument

It is not allowed

Both keywords is not allowed here

I don’t agree I made duplicated topics. Here I’m looking for a workaround for a problem and in closed topic I was wandering why is it made this way for the most obvious usecase for a generated column.

I’ve tested the functions. Your are turned to be right, sorry for misleading you – they are not allowed in generated columns. Why? Because it is integrated database functionality which prohibit the usage of non-deterministic functions.

For now it is possible to achieve what you need with dynamic properties in the request.
When you create a query to the table add the field like now() - birth as 'age' (please note that in REST console we have a bug which blocks the testing of dynamic properties, but it is only in UI).

So, I can update age with request. But if user didn’t login for more than a year there wasn’t any request that could update calculated age, so age will be incorrect. I have no idea how to automate it on backendless. It would be great if we could run some function on specific date, like recalculating age once a year on user’s birthday, but not creating manually a timer for each date. It would not be doable for any decent amount of users

Hi @Nik_AndroidDeveloper why would you think that each user needs it’s own timer? Instead just create one timer that runs every day at preset time, most likely at night, and for logic just load all users for whom current date/month matches their birthdate/month and loop through to recalculate actual age.

@Nik_AndroidDeveloper ,

Backendless provides timers functionality for scheduled code executions. In case if you want age to be stored in separate column in DB you can look to timers functionality. I think that timer per user will be not rational and it is better to use single timer in this case.

I would suggest you to use dynamic property instead, as Oleg has suggested. It will be optimal solution in this situation.

Regards, Andriy