Select to view content in your preferred language

Populate String or Date Field using Date and Time questions

976
2
Jump to solution
03-29-2023 03:49 PM
JBeasley
Occasional Contributor

Hello, 

We have a survey with a shift start and stop time. We need the user to enter specific times so we are using a Date type question and a separate Time type question to avoid the auto population of the time that occurs in a DateTime type question. 

Is it possible to then combine the Date and Time results and combine those in a single field? I have tried a few configurations and calculations, but frequently receive a type mismatch error. I'd essentially like to replace the "default" time that gets applied to a date/dateTime field with the user input...

Here is how I envision the date and time question configuration:

typenamebind::esri:fieldType
dateShiftStartDatenull
timeShiftStartTimenull

 

Here is a calculation I have tried for reference of what I am trying to achieve:

typenamecalculationbind::esri:fieldType
textShiftStartstring(format-date($ShiftStartDate, "%m/%d/%Y")) + " " + string(format-date($ShiftStartTime, "%h:%M"))esriFieldTypeString

 

I am open to the ShiftStart field being date or string type in the service. Thank you! 

0 Kudos
1 Solution

Accepted Solutions
ZacharySutherby
Esri Regular Contributor

Hello @JBeasley

You will need to use the concat() function to merge the strings together as opposed to the plus sign. With the plus sign Survey123 is trying to perform a mathematical addition with the values. The calculation would look like: 

concat(string(format-date($ShiftStartDate, "%m/%d/%Y")), " ", string(format-date($ShiftStartTime, "%h:%M")))

Thank you,
Zach

View solution in original post

2 Replies
ZacharySutherby
Esri Regular Contributor

Hello @JBeasley

You will need to use the concat() function to merge the strings together as opposed to the plus sign. With the plus sign Survey123 is trying to perform a mathematical addition with the values. The calculation would look like: 

concat(string(format-date($ShiftStartDate, "%m/%d/%Y")), " ", string(format-date($ShiftStartTime, "%h:%M")))

Thank you,
Zach
JBeasley
Occasional Contributor

Hi @ZacharySutherby ,

Thank you for the reply! I found the issue was likely due to missing curly brackets around my field name. The concat did work- thanks.

This was my final calculation formula:

if(string-length(${ShiftStartTime})!=0, concat(string(format-date(${ShiftStartDate}, "%m/%d/%Y")), " ", string(format-date(${ShiftStartTime}, "%H:%M"))), "")

0 Kudos