How to calculate age only when date of birth is filled?

I have this formula on a field to calculate the age of people:
dateDif({Date of Birth}, today(), “Y”)

It works well, except when the field “Date of Birth” is empty (on this case, the formula is returning “121”, which is 2021-1900). My question is: how can I create this formula, in order that nothing is returned when the “Date of Birth” is empty?
Thank you very much.

You need to nest the datedif inside an if function. This is how you can do it:

If you don’t like the zero, you can also just put ‘’.

1 Like

Hi! Thank you very much. Situation solved!
There is only one small issue: with this formula, the resulting number is showed on the left of the field, when it should be on the right (because it’s a number).
But SeaTable is detecting it as a “string” as you can see on this image (and I’m not finding a way to change the format of the field):


Is there any way to solve this situation and, at the end, have the resulting number on the right of the field?

Yes, there is!

To the right of the message “Current detected result type is string” is a button labelled “Re-detect”. Hit it! If the result type remains “string”, then sort the formula column. Make sure that a number is in the first row. Then hit “Re-detect” again.

SeaTable analyses the column top down. If it finds a string in the first row, it sets the result type to string. If there is a number … you get it.

1 Like

It worked. Thanks!
I think this trick should be explained somewhere on the documentation, as probably other users will face the same issue. :+1:

We’ll update the manual shortly.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.