I am a real rookie using Survey 123 and especially w/ the calculations (but I am not giving up)!
I used a formula that I researched to calculate and output hours and minutes:
(However, I don't know how to show the colon between the hours and minutes after running the form.
concat(int((${t2} - ${t1}) div (1000*60*60)), ":", if(int(((${t2} - ${t1}) div (1000*60)) mod 60) < 10,"0",""), int(((${t2} - ${t1}) div (1000*60)) mod 60))
The formula is quite long but I can hide some of the fields that I don't want to see.)
Or even if I am using the correct expression.
Please help w/'simple' if possible 🙂
Any help is appreciated.
Thanks.
Maybe another way is shown here, Solved: Calculate time between two date-times using a date... - Esri Community
and broken down into more bite-sized chunks:
#Considering your dates are epoch times, they represent the
#number of seconds #since 1970.
#Esri use milliseconds. so:
#ms_diff is the milliseconds (ms) between the two dates.
ms_diff = ${endtime} - ${starttime}
#there are 60,00 ms in a minute,
#3,600,000 ms in an hour.
decimal_hours = ${ms_diff} div 3600000
#round down using int
rounded_hours = int(${decimal_hours})
decimal_mins = ${ms_diff} div 60000
#round down using int
rounded_mins = int(${decimal_mins})
# rounded_mins is your total minutes difference between
#the two datetimes,
# if you use it alongside hours, you need to subtract
#the rounded hours*60 to get the minutes remainder.
#or take the modulus as below:
modulo_mins = ${rounded_mins} mod 60
#H, M padding and logic to pad a 0 if Hrs <10
times = if(${rounded_hours} < 10, '0' + ${rounded_hours}, ${rounded_hours}) + 'H:' + if(${modulo_mins} < 10, '0' + ${modulo_mins}, ${modulo_mins}) + 'M'
#I'd set all to visible to see what's going on and trial a few time #differences in the app, then set appearance field to 'hidden' as needed #after.
type | name | label | readonly | calculation |
dateTime | starttime | starttime | ||
dateTime | endtime | endtime | ||
decimal | ms_diff | ms_diff | yes | ${endtime} - ${starttime} |
decimal | decimal_hours | decimal_hours | yes | ${ms_diff} div 3600000 |
integer | rounded_hours | rounded_hours | yes | int(${decimal_hours}) |
decimal | decimal_mins | decimal_mins | yes | ${ms_diff} div 60000 |
integer | rounded_mins | rounded_mins | yes | int(${decimal_mins}) |
integer | modulo_mins | modulo_mins | yes | ${rounded_mins} mod 60 |
text | times | times | yes | if(${rounded_hours} < 10, '0' + ${rounded_hours}, ${rounded_hours}) + 'H:' + if(${modulo_mins} < 10, '0' + ${modulo_mins}, ${modulo_mins}) + 'M' |