How to Calculate Age

User question:
Need help with the Age computed field. Have a birthdate field and would like to calculate Age

You can use the following condition in calculated field:

Math.floor((new Date() - new Date( Birthdate ).getTime()) / 3.15576e+10)

Birthdate is birthdate field.

Just a note:
The calculated field is calculated just once, when the record is saved. So it is not good to use it for Age or similar things, which changes in time.
For some statistics you can use relative date filter (current date - 18 years e. g.) in a dashboard/grid.

1 Like

When I have two date pickers: At first one I want to just pick a date. At second one I want to get +14 days automatically when I will set the first date picker. How to?

Try this.

new Date(new Date(Date Received).setFullMonth(new Date(Date Received).getFullMonth() + 1)).toDateString()

This works for with the .setFullYear() and .getFullYear() functions when trying to a Date Received to add an expiration date.

Hope this helps!

Hi Thomas,
these kind of task I solve by custom javascript. So I would go to he advanced settings of the schema and I would use the
On model change tab and write a script like this:

if (doo.model.<[Date (x5c2qo4gyp)]>.value) {
	var d = new Date(doo.model.<[Date (x5c2qo4gyp)]>.value)
	var d14 = new Date(d.setDate(d.getDate() + 14)).toISOString();
    doo.model.<[Date + 14 (x7q7e2h50w)]>.value = d14;
 } else {
   doo.model.<[Date + 14 (x7q7e2h50w)]>.value = null;

For your field names please push Ctrl + Space for intellisence.
In the script you can setup, which fields are enabled, which are visible, values of the fields etc …

That works perfectly. Thanks a lot. :slight_smile:

Hi Michal,

Is it possible to make a counter out of this that would update automatically? I am currently using the following code but the item needs to be opened to update the date difference.

if (doo.model.<[Respond by (xcux5djoqn)]>.value) {
var d = new Date()
var dued = new Date(doo.model.<[Respond by (xcux5djoqn)]>.value)
doo.model.<[Due in (days) (xv6l3dpknf)]>.value = ((dued - d) /(1000 * 60 * 60 * 24 )).toFixed(0);
} else {
doo.model.<[Due in (days) (xv6l3dpknf)]>.value = null;


Hi Martti,
I am sorry. However, as I wrote here in this chat (May 26), this client javascript is meant to run only during record edit. The client javascript cannot be used for data, which changes in time.

1 Like