Forum Discussion
Conditional Formatting Dependant On Date
- Aug 11, 2023
Edd_Keogh Use this JSON column formatting for your date column:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if(Number(@currentField) == 0 , '', if(@currentField < addDays(@now, -7), 'red', if(@currentField < @now, 'yellow', 'green')))", "padding-left": "14px", "color": "=if(Number(@currentField) == 0, '', 'white')" } }
You can also refer the list column values in JSON using the internal name of column like [$StartDate]. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?
Also, here I have used Number(@currentField) == 0 to check date column is blank or not. You can find other ways to check if date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty
Output:
You can adjust the conditions as per your requirements if needed.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Edd_Keogh Use this JSON column formatting for your date column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if(Number(@currentField) == 0 , '', if(@currentField < addDays(@now, -7), 'red', if(@currentField < @now, 'yellow', 'green')))",
"padding-left": "14px",
"color": "=if(Number(@currentField) == 0, '', 'white')"
}
}
You can also refer the list column values in JSON using the internal name of column like [$StartDate]. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?
Also, here I have used Number(@currentField) == 0 to check date column is blank or not. You can find other ways to check if date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty
Output:
You can adjust the conditions as per your requirements if needed.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.