Calculate total time when start and end times field type is text

636
2
10-13-2017 12:42 PM
BonnieWeller1
New Contributor III

I am playing with different ways to enter time and calculate total time. I am considering capturing time in a text format because I have noticed that the now() option can be buggy under certain circumstances (like if the survey crashes, the time refreshes to recovery time. Also, the species sighted time captured in a repeat section refreshes my route start time under some conditions). I am wondering if it is possible to calculate total time is the time is captured as text (military time). If so, how?

Many thanks.

Tags (1)
0 Kudos
2 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Bonnie,

This is pretty easy to do - you need to have a calculation that extracts the hour part and minute part using substr(), converts the to integers and then does the subtraction.  Assuming you require a leading zeros for hour and minute, the function for the time in minutes is (t1 is start time, t2 is end time):

60*(int(substr(${t2}, 0, 2)) - int(substr(${t1}, 0, 2))) +  (int(substr(${t2}, 3, 5)) - int(substr(${t1}, 3, 5)))

That being said, we are improving the behavior of now() in the next release of Survey123.

BonnieWeller1
New Contributor III

Awesome. It worked great. I cannot wait to see your improvements. Most of my issues with the survey I just tested were with how time functioned in the App. (p.s I hope you are making the time wheel more user friendly. esp. if you don't use the now() function.)