Forum Discussion
JSON for Formatting Dates
AdmiralS I will share the simpler approach just use this that will help. I have also shown below the example I made for you.
This is the formula: You need to convert the days in to millisecond to compare. 30 days is 2592000000 milliseconds.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if([$ExpiryDate]<= @now+2592000000, '#ff0000', '')"
}
}Hopefully this helps and mark the response appropriately.
Thanks!
I need to color for 3 scenarios against the same column though -
Red - Dates Before Today
Yellow- Dates between Today and 30 days out
Green - Dates 30 days and forward from Today
Can I do that all in the same JSON conditional filter?
- Vikram_SamalMay 11, 2020MCT
AdmiralS Yes just you have to use multiple Ifs I have shown an example which can follow and modify as per your need.
This is the code:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "color": "=if([$Color] == 'Red', 'red', if([$Color] == 'Green', 'green',if([$Color] == 'Blue', 'Blue', if([$Color] == 'Yellow', 'Yellow', 'Orange'))))" } }Hope this helps mark the response appropriately if it helps to solve your problem.