Hi everyone,
I have a survey123 feeding a feature layer that I am using in a web map. Two of the questions are time questions, but they submit to the survey as 24 hour time. I am trying to use arcade to change the format to a 12 hour format, but the expression I think should be working isn't.
when I use
The Time function is meant to pull the time out of an actual DateTime or Time datatype. If I'm not mistaken, Survey123's Time question type stores a string, so there's nothing for the function to actually work with. You can use Arcade to read the string and modify it to show 12-hour time, though.
// split time by colon
var t = Split($feature['StartTime'], ':')
// get the hour as a number
var the_hour = Number(t[0])
// if the hour is 12 - 23, it's PM, otherwise AM
var am_pm = Iif(
the_hour >= 12,
'PM',
'AM
)
// if the hour is 0, re-write as 12
var hour_str = Iif(
the_hour == 0,
'12',
Text(the_hour, '#')
)
// return the various pieces of the time in one string
return `${hour_str}:${t[1]} ${am_pm}`
Fingers crossed this will work - just getting the weird issue with arcade having invalid variables.
That's really odd. I use Arcade this way all the time without issues. Does it let to attempt to run the code, or does it insist there's a problem?
Try adding Console(the_hour) above line 8, see if it sends anything to the console.
Oh sheesh. I forgot the closing quotation on line 11. Should be 'AM'.