Forum Discussion

57Andy's avatar
57Andy
Copper Contributor
Jan 24, 2024

Sharepoint List - Formatting codes for a date column and a choice column

Hi I'm trying to sort out a bit of code, but going nowhere. I have two columns one a date column (update date) that I want to turn red once the date hits 21 days old, so it acts as a reminder, the second column (status) is a choice column with 3 options (Not started, In progress and Closed) and when the status is changed to closed I want the "update date" column to turn green.

Can someone help me out with the coding for each column?

 

  • 57Andy Assuming you want to turn Update date field Red when there is no update for last 21 days (Update date is older than today - 21 days), you can use JSON column formatting for your update date column like: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "background-color": "=if([$Status]=='Closed', '#CAF0CC', if(@currentField < addDays(@now, -21),'#D13438',''))",
        "color": "=if([$Status]=='Closed', '#437406', if(@currentField < addDays(@now, -21),'#FFFFFF',''))",
        "padding-left": "15px"
      }
    }

     

    Where [$Status] is an internal name of your Status column in SharePoint list in this format: [$InternalNameOfColumn]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

     

    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.

Resources