Time question in 12 hour format in feature report

03-18-2021 11:44 AM
New Contributor II

In my survey I have work start and work end Time questions. In my feature report, they display in a 24 hour format. Is there any way to display these in a 12 hour format instead of 24 hour format? I really don't want to include the date using a DateTime question because the survey is only for one day so that just adds an extra step for users filling out my form and extra irrelevant information on the feature report. Also the Start and End questions won't work because I don't need the times the survey was started or completed. Is there a calculation that can give me a 12 hour format for the Time question in my feature report? 


2 Replies
Esri Regular Contributor

Hi @KelliW 

The time question type stores the time as a text string in "HH:mm" format. One way to convert this to a string that displays the time in 12-hour format would be to use a combination of if(), int(), substr(), format-date(), and concat() functions to take the hours, subtract 12 if required, and then append "AM" or "PM". Here is an attempt at a calculation (in a text question) using a time question named time1. Note that it might need some testing and refinement!

if(int(substr(format-date(${time1},'%h:%M'),0,2)) < 12, concat(format-date(${time1},'%h:%M'),' AM'), concat(int(substr(format-date(${time1},'%h:%M'),0,2))-12,':',format-date(${time1},'%M'),' PM'))

The condition checks if the hours are less than 12, in which case make this an AM time; else subtract 12 to get the 12-hour time and add 'PM'.

For a dateTime question you could use ${date_time | format:"hh:mm A"} in your report template to show the 12-hour time in the report and disregard the date portion (which is probably simpler, but appreciate you don't wish to use a dateTime question).

Check out the Dates and Time in Survey123 blog post for more useful info and examples for working with dates and time.

Hope this is useful. Best, Jim

New Contributor II

Thank you! I will try this out.

It does seem like the date/time question would be the easier option. It is good to know that I can just display time in my feature reports and hide the dates.

0 Kudos