Conditional formatting for Sharepoint List (<= 24H of today)

N PIERCE 5 Reputation points
2023-07-12T16:37:34.6966667+00:00

I am trying to get color coded conditional formatting for a column that includes "today(relative)" < or = 24 hours. I have no experience with JSON so any help would be greatly appreciated!

Below is the code for todays date only...

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            {
              "operator": "Date()",
              "operands": [
                {
                  "operator": "toDateString()",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        "[$Internal_x0020_Due_x0020_Date]"
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "operator": "Date()",
              "operands": [
                {
                  "operator": "toDateString()",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        "@now"
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        "sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont",
        "sp-css-backgroundColor-BgLightGray sp-field-fontSizeSmall sp-css-color-LightGrayFont"
      ]
    }
  },
  "txtContent": "[$Internal_x0020_Due_x0020_Date.displayValue]"
}
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Haoyan Xue_MSFT 22,466 Reputation points Microsoft Vendor
    2023-07-13T02:11:20.7733333+00:00

    Hi @N PIERCE,

    Based on your description, I understand that there is a date and time column in the list, if the time in the date and time column is less than or equal to current time plus 24 hours, the background shows red colour.

    Please try below JSON codes.

     {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "txtContent": "@currentField",  
       "style": {  
         "color": "black",  
         "background-color": "=if(@currentField >= @now - 86400000,'red',' ')"  
       }  
     } 
    
    
    

    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.