Select to view content in your preferred language

Arcade Hour() to return 12 hour clock?

1888
4
Jump to solution
06-28-2021 12:26 PM
BugPie
by
Frequent Contributor

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. ?

 

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

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

View solution in original post

4 Replies
DavidPike
MVP Frequent Contributor
BugPie
by
Frequent Contributor

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) 

Result1 Hour Later: Current Hour is: 14

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

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
BugPie
by
Frequent Contributor

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!