Conditional formatting SharePoint list based on time elapsed since date

Sam Clark 6 Reputation points
2022-04-29T08:27:04.4+00:00

I have a SharePoint list that I'm trying to write some JDSON code for
The field is a date/ time field
I want to highlight to users when >=24 hours has elapsed since the date/time such as by adding a red background to the text
However, every code I write results in a blank field when I view the list
Any suggestions?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,665 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 41,781 Reputation points Microsoft Vendor
    2022-05-02T06:45:02.097+00:00

    @Sam Clark

    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 one day, 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:

    198152-image.png


    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.