SOLVED

Lists - Conditional Formatting with two Dates 48 hours apart

New Contributor

Hello  All.

 

I have searched through the threads on this site but unable to find a solution. 

 

So I have a form which students use to request shift swaps, additional shifts, and cancel shifts. Though PA this form copies into a SharePoint list.

 

When a student cancels a shift I need the row to turn red IF the Logged date and SC- Shift Date fields (shown below) are within 48 hours of each other, for example:

 

If the logged date is 01/09/2022 and the SC- Shift Date is 03/09/2022 then I want to the row to turn red as a flag for a short notice shift cancellation.  

 

Angry_sys_Admin_1-1662042206095.png

 

To only formatting I can manage with these cells is if the date matches Today, or a fixed date in the future, I can't set it for 48 hours.


Any solution to this would  be greatly appreciated, I've only recently started managing SharePoint lists so still learning.


Thanks

 

 

2 Replies
best response confirmed by Angry_sys_Admin (New Contributor)
Solution

@Angry_sys_Admin you can do this with a simple piece of JSON view formatting. Click the dropdown next to All Items in the top right of the list and select Format current view. Click Advanced mode and paste in the following JSON code and save:

{
"additionalRowClass": "=if([$SCShiftDate] <= @now+172800000, 'sp-field-severity--severeWarning', '')"
}
 
Date comparisons are done in milliseconds, so 2 days is 172800000. You'll note that I don't like adding spaces into column names, it just makes the JSON code a bit more complex, but if you do have spaces you'll need to get the internal name of the column from List Settings -> select the column and in the address bar at the top select the name after Field=
 
0-SP-2Days.png

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
Rob, Many thanks for the solution.

At first it applied the formatting rule to everything in the list (just test cases) however it did apply correctly to all new entries thereafter.