I have a list and I want to display how old or how long ago a point was created. Is there a way to write this out so the list reads with the Incident and below it says: Occurred X Hours X Minutes ago
Solved! Go to Solution.
This was tested in a List
var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) {
var hours = Floor(diff/60)
var minutes = Floor(diff - (hours * 60))
if (diff < 60) {
output = `Occurred ${minutes} minutes ago`
} else {
output = `Occurred ${hours} hours ${minutes} minutes ago`
}
}
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
elapsed: output
}
}
In the Line item template section, add in "{expression/elapsed}".
This is what my testing List looks like:
Here's one way to do it.
Edit...made a few modifications
var creationTime = $feature.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes')
if (diff < 0) return `It hasn't occurred yet`
var hours = Floor(diff/60)
var minutes = Floor(diff - (hours * 60))
if (diff < 60) return `Occurred ${minutes} minutes ago`
return `Occurred ${hours} hours ${minutes} minutes ago`
@KenBuja thanks for your help with this. Did I input this correctly? I'm not to the advanced formatting section.
My apologies, this was tested in the Playground, not an indicator. Give this a try
var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) {
var hours = Floor(diff/60)
var minutes = Floor(diff - (hours * 60))
if (diff < 60) {
output = `Occurred ${minutes} minutes ago`
} else {
output = `Occurred ${hours} hours ${minutes} minutes ago`
}
}
return {
//textColor:'',
//backgroundColor:'',
topText: output,
//topTextColor: '',
//topTextOutlineColor: '',
//topTextMaxSize: 'medium',
@KenBuja Getting closer...I think. Not knowing much about arcade expressions, is having the date with the time causing an issue?
Attribute table:
This was tested in a List
var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) {
var hours = Floor(diff/60)
var minutes = Floor(diff - (hours * 60))
if (diff < 60) {
output = `Occurred ${minutes} minutes ago`
} else {
output = `Occurred ${hours} hours ${minutes} minutes ago`
}
}
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
elapsed: output
}
}
In the Line item template section, add in "{expression/elapsed}".
This is what my testing List looks like:
@KenBuja That worked! Thank you s much for your help, I appreciate it!