Forum Discussion

Jennife_r's avatar
Jennife_r
Copper Contributor
Jun 06, 2024

Formatting a Date Column to be red if expired, and gold is expiring within 5 days.

I know similar things have been asked but I can't find any available solutions that I could successfully tweak to work. Whenever I think I get close the formatting just makes the dates disappear 🤦‍:...
  • Jennife_r's avatar
    Jun 07, 2024

    Jennife_r 

    I was able to solves this using AI (after MUCH back and forth and rewording).

    The code that worked is ...

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "attributes": {
        "class": "=if(Number(@currentField) == 0, '', if(@currentField <= @now, 'sp-css-backgroundColor-BgCoral sp-css-borderColor-CoralFont sp-field-fontSizeSmall sp-css-color-CoralFont', if(@currentField <= @now + 432000000, 'sp-css-backgroundColor-BgGold sp-css-borderColor-GoldFont sp-field-fontSizeSmall sp-css-color-GoldFont', '')))"
      }
    }

    I hope this helps someone else!! 

Resources