Select to view content in your preferred language

Using Arcade to change Datetime from UTC to CST in Dashboard

2115
4
11-16-2022 02:05 PM
ThomasRickett
Regular Contributor

We have a data stream that is displaying times in GMT. We would like to changed multiple to CST (-6 hours). 

ThomasRickett_0-1668635950812.png

I see the Date functions in Arcade might work. 

https://developers.arcgis.com/arcade/function-reference/date_functions/#tolocal

DateAdd shows this

var startDate = Date($feature.dateField);

var oneWeekLater = DateAdd(startDate, 7, 'days');

return oneWeekLater;

Can I change that to 

var startDate = Date($feature.dateField);
var Sixhoursago = DateAdd(startDate, -6, 'hours');
return Sixhoursago;

ThomasRickett_1-1668636191659.png

I want to change all these fields.

ThomasRickett_2-1668636303841.png

 

0 Kudos
4 Replies
jcarlson
MVP Alum

Yes, date functions would be the way to go. Since you're doing this multiple times, you may also want to use a custom function.

function GMTtoCST(d){
    return DateAdd(d, -6, 'hours')
}

var d1 = Now()
var d2 = Date('2022', '5', '27', '15')
var d3 = Date('2017', '8', '11', '8')

Console(d1, GMTtoCST(d1))
Console(d2, GMTtoCST(d2))
Console(d3, GMTtoCST(d3))

jcarlson_0-1668691669341.png

 

- Josh Carlson
Kendall County GIS
ThomasRickett
Regular Contributor

Thank You Josh!

This is a big help. I need a bit more help with it since I'm not to familiar with Arcade. 


Do I replace d1-d3 with 

{bcs_time_first_unit_assigned}

{bcs_time_first_unit_arrived}

{bcs_response_time_depart}?

How would I call the function in the line item template to have just CST show?

ThomasRickett_0-1668789200870.png

Thank you so much again Josh!

0 Kudos
jcarlson
MVP Alum

Up in the Advanced Formatting area, you'd add these converted times to the attributes section, like this:

function GMTtoCST(d){
    return DateAdd(d, -6, 'hours')
}

return {
    attributes: {
        assigned: GMTtoCST($feature.bcs_time_first_unit_assigned),
        arrived:  GMTtoCST($feature.bcs_time_first_unit_arrived),
        departed: GMTtoCST($feature.bcs_response_time_depart)
    }
}

 

Then in your line item template, you pull out individual attributes like {expression/assigned} and so on.

- Josh Carlson
Kendall County GIS
SarahRijneke
Frequent Contributor

I've created an application that shows snow plow clearing in my city. It's supposed to show when a street was last plowed (under 4hrs ago, 4-8 hrs ago, 8-16 hrs ago, 16-24hrs ago). There is a 5hr delay between the timestamp field an my local time zone (EST) so the app isn't showing the data correctly. How can I use arcade to correct this?

Here's an example of my expression for the 16-24 hour time frame:

if (DateDiff ( now() ,  Date($feature.Time_Stamp) , 'hours' ) > 16 && DateDiff ( now() ,  Date($feature.Time_Stamp) , 'hours' ) <= 24 ){
    return "16-24 Hours"}
else {return "No Data"}

 

0 Kudos