Im trying to calculate age in months and days in Commcare. The calculation
will be done as 'current date - DOB'
I know you can do the calculation seperately as months, years, weeks or
days, but is there anyway to set a claculation and show the output as
months and days (e.g. 24 months, 15 days)?
There is an operator you can use in CommCare logic called "mod". You can
use it to get the remainder of days after you divide to get the number of
months.
···
On Wed, Oct 12, 2016 at 4:01 AM, Sabeth Ahmed wrote:
Hi,
Im trying to calculate age in months and days in Commcare. The calculation
will be done as 'current date - DOB'
I know you can do the calculation seperately as months, years, weeks or
days, but is there anyway to set a claculation and show the output as
months and days (e.g. 24 months, 15 days)?
···
On Oct 12, 2016 9:59 PM, "Amelia Sagoff" wrote:
Hi Sabeth,
There is an operator you can use in CommCare logic called "mod". You can
use it to get the remainder of days after you divide to get the number of
months.
On Wed, Oct 12, 2016 at 4:01 AM, Sabeth Ahmed smunrat@gmail.com wrote:
Hi,
Im trying to calculate age in months and days in Commcare. The
calculation will be done as 'current date - DOB'
I know you can do the calculation seperately as months, years, weeks or
days, but is there anyway to set a claculation and show the output as
months and days (e.g. 24 months, 15 days)?
You’re right—most simple age calculations give you only years, months, weeks, or days separately. To show something like “24 months, 15 days,” you need to do two steps:
Calculate the total number of months between the DOB and today.
Calculate the remaining days after subtracting those months.
So basically:
First, find how many full months have passed.
Then, take the leftover days after those months and display them together.
In CommCare, you might need to use a combination of date arithmetic functions and formulas to get both values and then join them in one display like: concat(months, " months, ", days, " days").
This will give the output exactly like “24 months, 15 days.”
You can calculate age in months and days in CommCare by first getting the total months, then subtracting full months to get the remaining days. Example approach: