Forum Discussion
Flaminia
Mar 03, 2022Copper Contributor
JSON on date field in Sharepoint List
Hello Is anyone able to help me with the JSON code to format a date field in Sharepoint? I want to format a certain column with dates in as follows: If the date is equal to todays date or an...
Don Kirkham
Mar 03, 2022MVP
Flaminia This should get you what you are looking for
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "white",
"background-color": "=if(toLocaleDateString(@currentField+1296000000) <= toLocaleDateString(@now), 'green', if(toLocaleDateString(@currentField+604800000) <= toLocaleDateString(@now) , 'orange', 'red'))"
}
}
You can learn more from here: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#apply-formatting-based-on-date-ranges
Good Luck!
Please click Mark as Best Response & Like if my post helped you to answer or resolve 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.
- FlaminiaMar 08, 2022Copper Contributor
Thank you so much Don Kirkham
I think that's almost there. I gave it a go but it seems to have colour coded the dates quite randomly!