Forum Discussion

kevingeorget's avatar
kevingeorget
Brass Contributor
Oct 24, 2019
Solved

JSON formatting a list view in SharePoint

Hi SharePoint Users, I need to format a Status column (Single line of text field) based on a Date- Time column for a SP List view.  The logic- 1. If [DueDate]<Today, then color is Bright Red 2. I...
  • kevingeorget's avatar
    Oct 24, 2019

    After some research, I've found a solution.

    We can user the toLocaleDateString() to extract just the date.

    so my expression would be-


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

Resources