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
RobElliott Would I be able to flag items that have a date that is older than a week before today's date? For example, I have an item with today's date (5/17/2023). In one week from today, I want this item to be flagged, and I want this to happen for all items.
At them moment, the formatting that I have is "if the variable is before a fixed date," but I don't want the date to be fixed - I want it to always be a week before today's date, if that makes sense.
jeremyELAM you can't do that with the built-in column formatting, but if you format the column in advanced mode you can paste in the following JSON which, in this example, will make the background color green until it's older than 7 days before today when it changes to maroon.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if(@currentField < @now-604800000, '#830909', '#409f93')",
"color": "white",
"padding-left": "10px"
}
}
This is the result.
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)