Hoping this is the correct place - New to Arcade.
Trying to get the Hour in a 12 hour clock format to return for a label and pop up. Currently showing the time in different time zone polygons. But I'm getting the 24 hour time since I am using the Hour() function.
Any advise to make this --> Hour(Now())-1
read in 12 hours instead when I add in a custom expression to the pop-up. ?
Solved! Go to Solution.
As to the final text you want, the format doesn't make a great deal of sense to me, also your description of 1 hour before, then wanting 1 hour after. I've written the code to make the timegap variable.
//negative for before, positive for after
var timeGap = 1
//add or minus x hours
var adjustedDate = DateAdd( Now(), timeGap, 'hours' )
//just the hours, no mins and AM/PM
//if u need mins also - 'h:mm A'
var adjustedDateTxt = Text(adjustedDate,'h A')
var beforeAfter = ''
if (timeGap >= 0) {
beforeAfter = 'Later'
}
else {
beforeAfter = 'Before'
}
adjustedDateTxt = Text(abs(timeGap)) + ' Hour(s) ' + beforeAfter + ': Current Hour is: ' + adjustedDateTxt
return adjustedDateTxt
How To: Add AM or PM in a web map pop-up (esri.com)
var n = Now(); Text(n,'h:mm A')
Hi David - thank you for that link. Works great when I use it as is!
Wondering if you had any advice as to how to use it with my custom expressions? I'm having trouble applying that to the below example. I am trying to get each label to display the time minus x hours from NOW. I'd like the below result to read "2" or "2PM" not "14"
Concatenate("1 Hour Later: Current Hour is: " , Hour(Now())+1)
Result | 1 Hour Later: Current Hour is: 14 |
As to the final text you want, the format doesn't make a great deal of sense to me, also your description of 1 hour before, then wanting 1 hour after. I've written the code to make the timegap variable.
//negative for before, positive for after
var timeGap = 1
//add or minus x hours
var adjustedDate = DateAdd( Now(), timeGap, 'hours' )
//just the hours, no mins and AM/PM
//if u need mins also - 'h:mm A'
var adjustedDateTxt = Text(adjustedDate,'h A')
var beforeAfter = ''
if (timeGap >= 0) {
beforeAfter = 'Later'
}
else {
beforeAfter = 'Before'
}
adjustedDateTxt = Text(abs(timeGap)) + ' Hour(s) ' + beforeAfter + ': Current Hour is: ' + adjustedDateTxt
return adjustedDateTxt
WOW! @DavidPike this is great. This is exactly what I was trying to accomplish, and you have verified that I was never going to get there myself, lol. I appreciate your time and insight on this - I'll certainly be using this to unpack and help teach myself. So helpful!