Forum Discussion

vballnewman's avatar
vballnewman
Copper Contributor
Jan 20, 2022

Conditional Formatting the most recent three days

I am trying to highlight all rows that have been added to my list in the last three days. The code below is what displays when I choose "on or after" "today". What I really want is "on or after" "today minus two days". How do I update my code to do this?

 

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"additionalRowClass": {
"operator": ":",
"operands": [
{
"operator": ">=",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Created]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"@now"
]
}
]
}
]
}
]
},
"sp-css-backgroundColor-BgPeach sp-field-fontSizeSmall sp-css-color-PeachFont",
""
]
}
}

1 Reply

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    vballnewman you can do this with shorter and easier to understand JSON as follows. You'll see that date comparisons are done with milliseconds:

     

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
        "elmType": "div",
        "style": {
            "background-color": "=if(@currentField >= @now-172800000,'#ffa558', '')"
        },
        "children": [{
                "elmType": "span",
                "style": {
                    "display": "inline-block",
                    "padding": "0 4px"
                },
                "attributes": {
                    "iconName": "=if(@currentField >= @now-172800000,'FavoriteStar', '')"
                }
            },
            {
                "elmType": "span",
                "txtContent": "@currentField"
            }
        ]
    }
    
    

     

    which results in:

     

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources