sharepoint 2016 JSON date formatting green today +30 days or more, orange if today - today +29 days, red if today or before sharepoint 2016

Ray Shadow 21 Reputation points
2022-11-01T17:26:33.263+00:00

I'm trying to modify some code that I found, I'm on SharePoint 2016 so I do not think I can use excel style. My column name is SSPDate and it is a date data type. I am trying to set up a dashboard so I can see what is overdue, coming due in the next 30 days, or 30 days or more out. I think this is the section I'm trying to modify I want to basically add 30 days to @now or what is a better way to accomplish this? I see quite a few posts very similar but have not been able to make them work.

{  
              "operator": ":",  
              "operands": [  
                {  
                  "operator": "==",  
                  "operands": [  
                    {  
                      "operator": "Date()",  
                      "operands": [  
                        {  
                          "operator": "toDateString()",  
                          "operands": [  
                            "@currentField"  
                          ]  
                        }  
                      ]  
                    },  
                    {  
                      "operator": "Date()",  
                      "operands": [  
                        {  
                          "operator": "toDateString()",  
                          "operands": [  
                            "@now"  
                          ]  
  
Microsoft 365 and Office | SharePoint | Development
{count} votes

Answer accepted by question author
  1. Yanli Jiang - MSFT 31,666 Reputation points Microsoft External Staff
    2022-11-03T08:19:37.107+00:00

    Hi @Ray Shadow ,
    As far as I know, JSON formatting will not work in the SharePoint 2016 classic experience, so please confirm that the version of SharePoint you are using is SharePoint 2019. You can refer to this method.
    According to my test, you can use the code as below:

    {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "txtContent": "@currentField",  
       "style": {  
         "background-color": "=if(@currentField <= @now, '#ff0000', if(@currentField >= @now + 2505600000, '#00ff00','#ffff00'))"  
      }  
     }  
    

    Then the result will be this:
    256570-11031.png

    For more information on column formatting of dates, please refer to here.
    *
    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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