You can use the “now()” function to get the current date and time. To use
the result it in calculations, you must convert it to a decimal value using
the “double()” function. The double function will convert the now() value
to a number that represents the date/time in days. This is similar to doing
calculations on dates, when you use int() to convert a date value into
number of days.
When the user “checks in” in you can capture the full date and time with a
hidden value with a calculation:
Save the hidden value to the case. When the user “checks out” you can load
that value into the “checks out” form (I’ll call the hidden value
Create another hidden value (I’ll call it ‘time_worked’) represent the
amount of time that has passed, by calculating:
double(now()) - double(/data/log_in_time)
The result is a decimal value in days/fractions of days. To convert to
hours and minutes, you can do the following calculations:
int(/data/time_worked * 24) = (rounded down) the # of hours
int(((/data/time_worked*24) - int(/data/time_worked * 24)) * 60) = (rounded
down) the # of minutes worked.
I know that’s a little bit complex. Please let me know if you need a hand
testing anything out or getting this to work.
On Sun, Apr 13, 2014 at 10:33 AM, Ameera Hamid wrote:
I am working on an electronic logbook for my first year students. in the
logbook there is a clock-in / clock-out module which contains forms to
clock in for the day and clock out at the end of the day. I would like to
calculate the hours and mins that they have worked and display it on the
clock out form when they are clocking out. I have seen commcare
documentation to support calculations using dates, but I am unsure of how
to calculate hours and minutes using time. is there a calculation/logic
Any help would be greatly appreciated!
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an
email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.