I'm creating an Arcade expression to feed a dashboard list. The expression groups on an ID to find the earliest date, then I want to find the difference between that date and todays date but DateDiff is returning blanks. I know that date formatting is picky in arcade. Its probably a formatting issue but I cannot figure it out.
Here is the code, which successfully returns a featureSet with a 'scheduled_date' and 'today_date' but 'days_remaining' is empty. I've exclude the connection steps since I know I'm successfully pulling in scheduled_date from the source.
// Group on area_id and get aggregate values
var groupedRequests = GroupBy(hydrant_requests, ['area_id'],
[
{name: 'ScheduledDate', expression: 'schedule_date', statistic: 'MIN'}
]
);
var resultFeatures = [];
var feat
var today_date = Today()
// create a feature array which combines the grouped values + a calced field
for (var record in groupedRequests)
{
feat = {
attributes:
{
'area_id': record['area_id'],
'scheduled_date': Number(record['ScheduledDate']),
'today_date' : Number(today_date),
'days_remaining': DateDiff(Number(record['ScheduledDate']), Number(today_date), 'days')
}
}
// Add each feat result to the resultFeatures array
Push(resultFeatures, feat);
};
// Create a dictionary from the feature array
var myDict = {
'fields': [
{ name: 'area_id', type: 'esriFieldTypeString' },
{ name: 'scheduled_date', type: 'esriFieldTypeDate' },
{ name: 'today_date', type: 'esriFieldTypeDate'},
{ name: 'days_remaining', type: 'esriFieldTypeInteger'}
],
'geometryType': '',
'features': resultFeatures
};
// Convert dictionary to feature set which can be used in the widget
var fs_dict = FeatureSet(Text(myDict));
return fs_dict;
Result:

Any ideas appreciated. Thanks!