SharePoint expiration date format

andare smith 0 Reputation points
2023-04-26T13:53:14.13+00:00

So I have a column within my sharepoint list that calculates an expiration date based off a previously inputted date. What I am asking now is how do I format or create a json code to turn the column red when the expiration date is within 30 days or closer, yellow when within 60 days, and all other times green?

Microsoft 365 and Office Install, redeem, activate For business Windows
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 24,941 Reputation points Moderator
    2023-04-27T02:53:39.92+00:00

    Hi @ andare smith ,

    Use JSON code like below. Don't forget to replace the variable with your own.

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

    Test result:

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.