Select to view content in your preferred language

Using Arcade to change Datetime from UTC to CST in Dashboard

1242
3
11-16-2022 02:05 PM
ThomasRickett
Occasional 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
3 Replies
jcarlson
MVP Esteemed Contributor

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
Occasional 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 Esteemed Contributor

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