Select for Today in Arcade when data is in local time

426
3
01-13-2023 03:25 PM
MeleKoneya
Occasional Contributor III
I published a feature layer to AGOL via ArcGIS pro and see in the data panel that our times are in local time which is what I wanted.
 
I am trying to grab only today's records using this:
 
var time = -1
var units = 'days'  //milliseconds, seconds, minutes, hours, days, months, years
var dateField = "Today"
var pastDate =  DateAdd(Date(), time, units)
if($feature.dispatch_date > pastDate)
{
  return dateField  
}
 
The results are close to what I would expect 110 records, but it really should be 75.   
 
I am guessing it is doing some UTC assumptions on my dates, but I am lost as to how to fake it to use the stored value which is local as far as I can tell since I published it that way.
 
Thanks,
 
Mele 
Tags (2)
0 Kudos
3 Replies
JayantaPoddar
MVP Esteemed Contributor

The following expression converts UTC date to to Local Date. Replace Timestamp() with your date variable.

ToLocal(Timestamp())

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



Think Location
MeleKoneya
Occasional Contributor III

I think I am getting closer to what I wanted.   

I had to get just the date part of today.

2023-01-14T00:00:00-07:00 with the Text Function

var dispatch = $feature.dispatch_date

var Today = Date(Text(now, "Y-MM-DD"))

If (dispatch > Today)

{

  'today'

}

else

{

  'past'

}

 

Mele

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Assuming the dispatch_date field also has Date datatype, you can check the following expression

 

var dispatch = $feature.dispatch_date

var dispatchdate = Concatenate(Year(dispatch),'-',Month(dispatch)+1,'-',Day(dispatch))

var currentdate = Concatenate(Year(Today()),'-',Month(Today())+1,'-',Day(Today()))

If (dispatchdate == currentdate)

{

  'today'

}

else

{

  'past'

}

 

 



Think Location