question

SamClark-1802 avatar image
0 Votes"
SamClark-1802 asked saldana-msft edited

Conditional formatting SharePoint list based on time elapsed since date

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-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered EmilyDu-MSFT commented

@SamClark-1802

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.



image.png (7.6 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SamClark-1802

I’m checking how the things are going on about this issue. Whether the answer helps you?

If there is any problem with this issue, feel free to let me know.

0 Votes 0 ·

Hi @EmilyDu-MSFT

Thanks for the reply

Unfortunately that didn't work. You are correct - one column is a date/time field. However, with those JSON codes even date/times 4 hours ago are shown with a red colour background. Any ideas what might be up?

199458-screenshot-2022-05-06-090924.jpg


0 Votes 0 ·

@SamClark-1802

I want to confirm, whether your requirement is that the time in the date and time column is less than or equal to current time plus one day, the background shows red colour?

0 Votes 0 ·