Date calculation and unique identifier

Hi everyone !

I am currently building a questionnaire for a screening campaign and I’d like to create automatically calculated identifier based on the data in the questionnaire. So far, I have found this formula which seems to work well :

My question is on this specific part : round(${today}-${dateofbirth},0). I would like to understand how Kobo calculates this equation.
example : for the today date of 2020-04-25 and birthdate of 1995-08-24 I get the number series 27743. Does someone know the math behind it?

I have also thought of simply using the _id meta data variable. How could I make it visible in my questionnaire ? We need to give this number to the persons we interview so they can get their screening results. Our staff also needs to reopen the questionnaire and fill additional questions when they receive the person’s screening results.

thanks a lot !


Try this instead:

round(decimal-date-time(${today}) - decimal-date-time(${dateofbirth}),0)

The decimal-date-time() function converts a DATE type to the number of days since a predefined epoch (Jan 1 1970 as it happens). So taking the difference gives you the number of days between today and the date of birth. [so if you want years, months, or weeks instead then divide this # days value appropriately].

1 Like

Great thanks !

If I wanted to be even more precise and get the number of hours, is there a formula for that ??


Decimal-date-time() will actually convert a dateTime (!) to its corresponding fractional days since the epoch. So yes if to take the difference between two dateTime timestamps you’d get a result of, say 123.3, which corresponds to 123 days, 7hrs and 12 minutes.