0

This should be simple and I hope it is.

I'm trying to get a date column to format in the following way:

If the date is GREATER than 2 weeks leading up to the date, its green

Is the date is LESS than 2 weeks until the date, its amber/yellow

If its past the date, its red.

However, if there is NO date input, it does nothing.

I've tried all I can with JSON, but it just alludes me. Any ideas? I can't seem to do it with the built in tools.

2 Answers 2

1

Try using below JSON, it should work for you:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
        "color": "black",
        "background-color": "=if(Number(@currentField) == 0, '', if(@now > @currentField, 'red', if(@now > addDays(@currentField, -14), 'green', 'yellow')))"
    }
}

OR

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
        "color": "black",
        "background-color": "=if(Number(@currentField) == 0, '', if(@now < addDays(@currentField, -14), 'yellow', if(@now > addDays(@currentField, -14) && @currentField >= @now, 'green', 'red')))"
    }
}

Output:

enter image description here

Documentation: SharePoint column formatting

Related read: SharePoint JSON formatting: Check if date & time column is blank/empty

1
1

Please try below codes.

 {
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
     "color": "black",
     "background-color": "=if(@currentField>@now + 1209600000,'green', if((@currentField>=@now) && (@currentField<@now + 1209600000),'yellow', if(Number(@currentField) == 0, ' ', 'red')))"
   }
 }

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.