Forum Discussion
Conditional Formatting Files Older Than Certain number of days or years
- Apr 25, 2020
Hi Michael, (pnthrzrule), yes we do this at our company. The JSON is below and subtracts 2 years (in milliseconds) from today's date. If the Modified date is older than that then the date is red, otherwise it's green:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "color": "=if([$Modified] <= @now-63113904000, '#c64444', '#468757')" } }
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Hi Michael, (pnthrzrule), yes we do this at our company. The JSON is below and subtracts 2 years (in milliseconds) from today's date. If the Modified date is older than that then the date is red, otherwise it's green:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if([$Modified] <= @now-63113904000, '#c64444', '#468757')"
}
}
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Also...one more question...It appears that JSON applied to a library affects ALL views. Is there a way to restrict this to just the active view to which I'm adding the JSON?
- RobElliottApr 30, 2020Silver Contributor
pnthrzrule sorry for the delay in replying Michael. From the menu where your views are listed, select Format current view. In the example below I've got the All items view in standard list format, but in the view that I've named Tile I've formatted the items differently with JSON:
Rob
Los GallardosMicrosoft Power Automate Community Super User
- pnthrzruleApr 30, 2020Iron Contributor
Thanks so much for the video. I swear I only applied the json (Red files older than 2 years) to only 1 view. However, for some reason, that formatting seemed to bleed over into all views. I will do some more testing. Thanks again.
- RobElliottApr 30, 2020Silver Contributor
pnthrzrule if you apply the formatting to the column (from the column header) then it will be there in all views. If you apply formatting to the view then it won't.
Rob
Los Gallardos
Microsoft Power Automate Community Super User