ODK Survey: calculating age in javascript

I am using these three calculations to get age in days, years, and months (
the reason is i need to know for very young children how many months old
they are so that you can prescribe malaria meds)

daysOld (now().getTime()-new Date(data('bday')).getTime())/1000/60/60/24
monthsOld data('daysOld') % 30 yearsOld data('daysOld') % 365

So, The days figure up correctly, but the months and years show up all
crazy wrong.

In the survey, these calculates look at the date selected for the birthday,
and then assign values to variables.

assign integer daysOld calculates.daysOld()
assign integer monthsOld calculates.monthsOld()
assign integer age calculates.yearsOld()

And then I read them back out in a note, just to check them:

Confirm birthday is {{data.bday}} confirm daysOld is {{data.daysOld}} and
confirm monthsOld is {{data.monthsOld}} and confirm age is {{data.age}}

But it comes out like this:

What thinkest thou?

image

image

SOLVED:
I was using module (%) instead of divide (/) !

··· > daysOld (now().getTime()-new Date(data('bday')).getTime())/1000/60/60/24 > monthsOld data('daysOld') % 30 yearsOld data('daysOld') % 365 > >

That's funny. You had me following right along with you!

··· On Fri, Apr 10, 2015 at 11:51 PM, Neil Hendrick wrote:

SOLVED:
I was using module (%) instead of divide (/) !

daysOld (now().getTime()-new Date(data('bday')).getTime())/
1000/60/60/24 monthsOld data('daysOld') % 30 yearsOld data('daysOld')
% 365

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com