Forum Discussion
Quick JSON formula question regarding date plus 365
- Apr 13, 2020
Is this what you are looking for?
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if([$DateColumn] >= @now + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}I hope this helps.
Norm
- alandarrApr 13, 2020Brass Contributor
Norman Young Taking another look at that, it still isn't working correctly. I'm trying to color it if it is more than 365 days old from today, i.e. more than a year old.
I've tried to move the formula around, but I still can't get it to do that. Not sure what's going on LOL!
- Norman YoungApr 13, 2020MVPShare your code and what is the column name (internal)?
- alandarrApr 14, 2020Brass Contributor
Norman Young The code works, but your example date is in the future. What I am trying to do is color the text when the date is past one year old. The attached example (screenshot) is your code with a date that is over 365 days in the past. The text is unchanged. It seems simple enough, but I've struggled with it for a couple days before you took a crack at it. Makes me crazy!
If you move the items around, a date that is less than a year old still shows as colored and bold. It's only supposed to do that if it's more than a year old.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "attributes": { "class": "=if(@now >= [$Expiration] + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')" } }