Select to view content in your preferred language

Survey123 Date Time Calculation

5977
5
08-24-2017 12:09 PM
JohnBroecher
New Contributor III

Most of our Survey123 forms do not require a time entry that is different than the current time. One particular survey does need a time manually entered and the time spinner is proving to be very disliked. I've been asked to come up with a way to enter time as an integer. I have a date field that defaults to today which is what we want, and then the time is entered as a single 24-Hr clock integer (12:15 AM = 0015 or 15, 3:59 PM = 1559). I have a constraint that checks if its a valid time. What I would like to do now is combine the date field with the integer and make a DateTime hidden field.

constraint on time integer:

(round(${FishingStartTimeInt}-50,-2)<2400) and ((${FishingStartTimeInt}-(round(${FishingStartTimeInt}-50,-2)))<60)

For the calculation I have this non-working code:

format-date(Date('1970-01-01') + int(${FishingStartDate})+int(((round(${FishingStartTimeInt}-50,-2))div100)*3600000)+int((${FishingStartTimeInt}-(round(${FishingStartTimeInt}-50,-2)))*60000),'%m/%d/%Y %H:%M')

I get the error cannot handle Date function. Any suggestions?

0 Kudos
5 Replies
RalphBeishline
New Contributor III

Tacking myself to this question as I have also received feedback from field staff who did not enjoy the time spinner and am interested in potential alternatives.

"I have entered three now and this method is very easy except for one thing. That spinning wheel for the time is awful.  It takes just as long to click on the time you visited a sight [sic] as it does to fill out the entire form." 

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi John,

The issue is that date must be lower-case.  While the calculations look javascript-esque, it sin't actually javascript you're writing- there's an interpretation element in between.

That being said, there's a much simpler way to set up text fields for date colleciton

typenamelabeldefaultcalculationbody::esri:inputMask
textdatetextDateText99/99/9999
texttimetextTimeText99:99
textutcoffsetUTC Offset-07:00
calculateyearYearsubstr(${datetext}, 6, 10)
calculatemonthMonthsubstr(${datetext}, 3, 5)
calculatedayDaysubstr(${datetext}, 0, 2)
notedatestringcompiled stringconcat(string(${year}),'-',string(${day}),'-',string(${month}),'T',${timetext},':00', ${utcoffset})
dateTimedateobjthe Dateif(string-length(${datetext}) > 0 and string-length(${timetext}) > 0, date-time(${datestring}), null)

Obviously, you can consolidate the steps being done (though in 2.4, you can specify that the intermediate fields won't submit)

JohnBroecher
New Contributor III

Thanks for the reply James. 

Collecting date and time as text seems to make the full keyboard open instead of the number pad, and it would need a constraint to only accept valid dates/times. I am kind of set on collecting date as date and time as integer for this one.

I changed the Date to lowercase and it allows publishing but it won't allow me to submit from the device. It gives a code 1000 string or binary data would be truncated. In connect when I view the data from 'Validate Input' it shows:

"FishingStartTime": "SyntaxError: Unexpected token `identifier' in expression: format-date(date('1970-01-01') +int( /Lakes_Creel_Survey/Interview/PartyInfo/FishingStartDate )+int(((round( /Lakes_Creel_Survey/Interview/PartyInfo/FishingStartTimeInt -50,-2))div100)*3600000)+int(( /Lakes_Creel_Survey/Interview/PartyInfo/FishingStartTimeInt -(round( /Lakes_Creel_Survey/Interview/PartyInfo/FishingStartTimeInt -50,-2)))*60000),'%m/%d/%Y %H:%M')",

I probably don't need the 1970 date in there at all since it is interpreted as zero. I put it there hoping it would help the expression be evaluated as a date.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

The format-date function should not be used - that's for generating a human-readable string from a date.  

0 Kudos
JohnBroecher
New Contributor III

Thought I'd share what I'm going to try using. It allows you to type the time as an integer, then it checks that its a valid time and stores it in a hidden field as a string in 00:00 format.

0 Kudos