Forum Discussion
ZoeBevs
Jul 07, 2023Copper Contributor
JSON help for formatting date column with colours
Help, Can someone tell me the JSON code to format my date column so the text changes colours based on date ranges? Red if date is today or before Orange if date is within 6 months Green if dat...
- Jul 07, 2023
ZoeBevs Try this:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "font-weight": "bold", "color": "=if(Number(@currentField) == 0, '', if(@currentField <= @now, 'red', if(@currentField > addDays(@now, 180), 'green', 'orange')))" } }Related threads:
- SharePoint JSON formatting: Check if date & time column is blank/empty
- How to find the Internal name of columns in SharePoint Online? - Always use internal name of columns in JSON if you are referring to another column value in column formatting
Output:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
ganeshsanap
Jul 07, 2023MVP
ZoeBevs Try this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"font-weight": "bold",
"color": "=if(Number(@currentField) == 0, '', if(@currentField <= @now, 'red', if(@currentField > addDays(@now, 180), 'green', 'orange')))"
}
}
Related threads:
- SharePoint JSON formatting: Check if date & time column is blank/empty
- How to find the Internal name of columns in SharePoint Online? - Always use internal name of columns in JSON if you are referring to another column value in column formatting
Output:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
ZoeBevs
Jul 07, 2023Copper Contributor
Thanks so much for this, it worked a treat 🙂