Forum Discussion
How to conditionally format a date column that is two weeks old?
- Dec 15, 2022
StephDH246
If you want to get the number of milliseconds since 01.01.1970, you need the expressionNumber(Date([$Created]))
So if you want to select all Dates before two weeks ago you could use the formula
Number(Date([$Created]))<(Number(Date(@now))-1209600000
(1209600000 = 14 * 24 * 60 *60 *1000).
You can access other fields in the view. If you have a field "CellToBeEmpty" and that field is in the view, then you can access the value of the field like this : [$CellToBeEmpty]
With two nested "if" statements, your json would look like this{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "style": { "box-sizing": "border-box", "padding": "0 2px", "overflow": "hidden", "text-overflow": "ellipsis" }, "attributes": { "class": "=if([$CellToBeEmpty],'',if(Number(Date([$Created]))<(Number(Date(@now))-1209600000),'sp-css-backgroundColor-BgRed sp-css-borderColor-CoralFont sp-field-fontSizeSmall sp-css-color-WhiteText',''))" }, "txtContent": "[$Created.displayValue]" }
StephDH246
If you want to get the number of milliseconds since 01.01.1970, you need the expression
Number(Date([$Created]))
So if you want to select all Dates before two weeks ago you could use the formula
Number(Date([$Created]))<(Number(Date(@now))-1209600000
(1209600000 = 14 * 24 * 60 *60 *1000).
You can access other fields in the view. If you have a field "CellToBeEmpty" and that field is in the view, then you can access the value of the field like this : [$CellToBeEmpty]
With two nested "if" statements, your json would look like this
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"box-sizing": "border-box",
"padding": "0 2px",
"overflow": "hidden",
"text-overflow": "ellipsis"
},
"attributes": {
"class": "=if([$CellToBeEmpty],'',if(Number(Date([$Created]))<(Number(Date(@now))-1209600000),'sp-css-backgroundColor-BgRed sp-css-borderColor-CoralFont sp-field-fontSizeSmall sp-css-color-WhiteText',''))"
},
"txtContent": "[$Created.displayValue]"
}
- StephDH246Dec 20, 2022Copper Contributor
SvenSieverding Thank you, this worked!