Forum Discussion

ZoeBevs's avatar
ZoeBevs
Copper Contributor
Jul 07, 2023
Solved

JSON help for formatting date column with colours

Help,   Can someone tell me the JSON code to format my date column so the text changes colours based on date ranges? Red if date is today or before Orange if date is within 6 months Green if dat...
  • ganeshsanap's avatar
    Jul 07, 2023

    ZoeBevs Try this: 

     

     

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

     

     

    Related threads:

    1. SharePoint JSON formatting: Check if date & time column is blank/empty  
    2. How to find the Internal name of columns in SharePoint Online? - Always use internal name of columns in JSON if you are referring to another column value in column formatting

    Output


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.