Whats the number of times the letter o appears in:
Q: Formatting a date column with various factors This should be simple and I hope it is.
Im trying to get a date column to format in the following way:
If the date is GREATER than 2 weeks leading up to the date, its green
Is the date is LESS than 2 weeks until the date, its amber/yellow
If its past the date, its red.
However, if there is NO date input, it does nothing.
Ive tried all I can with JSON, but it just alludes me. Any ideas?
I cant seem to do it with the built in tools.

A: Please try below 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 + 1209600000,green, if((@currentField>=@now) && (@currentField<@now + 1209600000),yellow, if(Number(@currentField) == 0,  , red)))
   }
 }

Result:


A: Try using below JSON, it should work for you:
{
    $schema: https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json,
    elmType: div,
    txtContent: @currentField,
    style: {
        color: black,
        background-color: =if(Number(@currentField) == 0, , if(@now > @currentField, red, if(@now > addDays(@currentField, -14), green, yellow)))
    }
}

OR
{
    $schema: https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json,
    elmType: div,
    txtContent: @currentField,
    style: {
        color: black,
        background-color: =if(Number(@currentField) == 0, , if(@now < addDays(@currentField, -14), yellow, if(@now > addDays(@currentField, -14) && @currentField >= @now, green, red)))
    }
}

Output:

Documentation: SharePoint column formatting
Related read: SharePoint JSON formatting: Check if date & time column is blank/empty

user
I found 95 "o"s in the provided passage.
assistant