Mar 07 2023 03:54 AM
Hi
I have a column called "Last Reviewed / Updated" which is a date field - i would like to highlight just the field red and have the text white and bold to indicate that 7 days has passed since the last review.
If the review was within 7 days the column should remain unformatted.
Could anyone assist with the JSON to do this please?
Mar 07 2023 04:20 AM
Hi @robrkhw;
this should work
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(floor((Number(@currentField)-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))<-7,'ms-fontColor-red','')"
},
"txtContent": "=@currentField"
}
If the difference in Days between the current field and now is less that "-7" then add the class "ms-fontColor-red"
Best Regards,
Sven
Mar 07 2023 05:05 AM
Solution@robrkhw Use this JSON column formatting for your date column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"color": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'white', '')",
"background-color": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'red', '')",
"font-weight": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'bold', '')",
"padding-left": "10px"
},
"txtContent": "=@currentField"
}
Output:
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.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 07 2023 05:14 AM
@ganeshsanap @SvenSieverding Thanks to both of you - both methods work, i just prefer the way @ganeshsanap code highlights the whole background.
Mar 07 2023 05:05 AM
Solution@robrkhw Use this JSON column formatting for your date column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"color": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'white', '')",
"background-color": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'red', '')",
"font-weight": "=if(Number(@currentField) != 0 && addDays(@currentField,7) < @now, 'bold', '')",
"padding-left": "10px"
},
"txtContent": "=@currentField"
}
Output:
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.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs