I created a Survey123 for road construction which includes two date type fields, one for when the construction begins and one field for when the construction ends, and I want to symbolize the features using those two date fields. Specifically I want to symbolize the features by what happened last week, "Construction Started Last Week", "Construction Ended Last Week", "Construction Was Active Last Week", and an "Other" symbology for those features whose start construction date and end construction date are outside the last week parameters.
//Here is an expression I tried to use to symbolize this, but it didn't work, every feature had "Other" symbology:
var startedlastweek = DateDiff(Now(), $feature.start_closure,'days');
var endedlastweek = DateDiff(Now(), $feature.end_closure, 'days');
If (startedlastweek >= 1 && startedlastweek <= 7) {
return "Active last week"
}
else if (endedlastweek >= 1 && endedlastweek <=7) {
return "Ended Last Week"
} else{
return "Other"
}
Thank you for the help!
Solved! Go to Solution.
if ( A <= 7 && now() < $feature.start_closure )
else if ( B <= 7 && A > 7 && now() < $feature.end_closure )
OR
var start = $feature.start_closure
var end = $feature.end_closure
var A = DateDiff(Now(), start , 'days' )
var B = DateDiff(Now(), end , 'days' )
var Condition = Null
if ( A <= 7 && start < now()){ Condition = "Active last week" }
else if ( B <= 7 && A > 7 && end < now() ){ Condition = "Ended Last Week" }
else { Condition = "Other" }
Console( Condition )
return Condition
Insert either of the characters below in parentheses if you want to combine statements
Try throwing in Console(startedlastweek) and see what it's returning. DateDiff usually expects the later date to come first, so you might be getting negative numbers?
Hi @brandonmann3,
Try this:
var A = DateDiff(Now(), $feature.start_closure , 'days' )
var B = DateDiff(Now(), $feature.end_closure , 'days' )
var Condition = Null
if ( A <= 7 ){ Condition = "Active last week" }
else if ( B <= 7 && A > 7 ){ Condition = "Ended Last Week" }
else { Condition = "Other" }
Console( Condition )
return Condition
Thank you for the quick response @RPGIS it works almost perfectly. The only problem with it though is if the feature's start date is today or in the future it is symbolized as "Active last week".
Features with a start date today or in the future, and an end date of today or in future it is labeled as "Ended last week".
Is the limitation of the DateDiff function that it cannot tell the difference between positive and negative difference, and I should be using something else for this symbology?
The two highlighted examples show the symbology issue I described:
Thank you again.
Hi @brandonmann3,
You could set it to identify if the future date is greater than now which would solve your issue.
Add now() < $feature.start_closure to the first if statement and now() < $feature.end_closure to the second if statement and that should work.
Sorry I'm a bit inexperienced with arcade, where exactly do I need to put that in each line?
if ( A <= 7 && now() < $feature.start_closure )
else if ( B <= 7 && A > 7 && now() < $feature.end_closure )
OR
var start = $feature.start_closure
var end = $feature.end_closure
var A = DateDiff(Now(), start , 'days' )
var B = DateDiff(Now(), end , 'days' )
var Condition = Null
if ( A <= 7 && start < now()){ Condition = "Active last week" }
else if ( B <= 7 && A > 7 && end < now() ){ Condition = "Ended Last Week" }
else { Condition = "Other" }
Console( Condition )
return Condition
Insert either of the characters below in parentheses if you want to combine statements
Thank you so much for your help this was great. I added an additional line to include any features created before last week and end after today.