1

I've been reading a lot of questions and answers, and I still can't figure out how to get this to work, so I'll ask here.

I have a Microsoft Form that I've connected to my SharePoint list. One of the questions on the Form asks users to select a date. When the date appears in the SharePoint list, I want its background color to be determined by how distant in time that date is relative to today.

I want the background to be green if the date is more than 180 days away, yellow if it's equal to or less than 180 days away, orange if it's equal to or less than 90 days away, and red if it's in the past.

I used Photoshop to find hex codes of the four shades I want: green (#72cf68), yellow (#e9e372), orange (#eb8147), red (#d13e3e).

Below is the code I made after reading many different questions and answers. I can't figure out why it won't work.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(Number(@currentField > @now + 15552000000, '#72cf68', if(@currentField <= @now + 15552000000, '#e9e372', if(@currentField <= @now + 7776000000, '#eb8147', if(@currentField < @now, '#d13e3e'))))"
  }
}

Thank you for reading.

1 Answer 1

0

Try using this JSON:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "font-weight": "bold",
    "padding-left": "10px",
    "color": "white",
    "background-color": "=if(Number(@currentField)==0, '', if(@currentField <= @now, '#d13e3e', if(@currentField > @now && @currentField <= addDays(@now, 90), '#eb8147', if(@currentField > addDays(@now, 90) && @currentField <= addDays(@now, 180), '#e9e372', if(@currentField > addDays(@now, 180), '#72cf68', '')))))"
  }
}

Output:

enter image description here

Similar thread: Color coding Modified Date

2
  • 1
    This is exactly what I had hoped to create. Thank you very, very much for the help, Ganesh!
    – PhilMark
    Commented Mar 10, 2023 at 15:58
  • Great, glad it worked for you! Keep using this platform for asking questions related to SharePoint. Commented Mar 10, 2023 at 16:06

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.