Question

I am trying to format a sharepoint list with JSON so that the From/To column highlights the current phone number when todays date falls into the timespan given.

enter image description here

I have managed to have past on future dates highlighted with the template from microsoft but it doesn't work properly when trying to highlight todays phone number. I guess it has to do with the fact that time needs to be considered as well.

enter image description here

Very many thanks for any help!

Best regards,

Tom

Was it helpful?

Solution

Time component is considered automatically.

If I understood correctly what you want it that is Today(date and time) falls between From and To date, you need to highlight phone number.

Idea is to check and compare today's date with From and To one by one.

Pseudo code

If today <= From 
  Do not format
Else
   if today<= To
      Format
   Else
      Do not format.  

I used below JSON

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
      "color": "=if(@now <= [$From], '',if(@now <= [$To],'#ff0000',''))"
   }
}

Below is output

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top