Forum Discussion
brankocareer
Jan 15, 2025Copper Contributor
JSON code to format date column
Hi, Can someone tell me the JSON code to format my date column in a list? I would like a date to show as "Fri, Jan 17, 2025", and if possible mark the weekend as RED color. Thanks in advance! Bran...
Rob_Elliott
Jan 16, 2025Bronze Contributor
Yes this is possible, but for the long date you will need to create a calculated column with the formula:
=TEXT(YourDateColumn,"ddd, mmm dd, yyyy")
Then, because the long date column now has text values, you need to look for those days starting with an S for Saturday or Sunday. You do this using the indexOf function in JSON. So if the letter S is at the very start of the long date (index position 0) then set the color to red, otherwise leave it as black
{"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if(indexOf(@currentField, 'S')== 0,'#ff437f','#000000')"
}
}
This is the result:
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)