Share via

JSON help for SharePoint column formatting

Anonymous
2025-01-09T15:01:12+00:00

How would I go about adding this -----  if the date field = 01/01/1900 it makes the text turn Grey? The rest of the below remains as it is

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

"elmType": "div",

"txtContent": "@currentField",

"style": {

"color": "=if(@currentField <= @now, 'crimson',if(@currentField <= @now + 1209600000 && @currentField > @now,'orange','green'))",

"font-weight": "=if(@currentField <= @now, 'bold',if(@currentField <= @now + 315576000000 && @currentField > @now,'bold','green'))",

"font-size": "=if(@currentField <= @now, '14px',if(@currentField <= @now + 315576000000 && @currentField > @now,'14px','green'))"

}

}

Microsoft 365 and Office | SharePoint | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2025-01-13T13:39:28+00:00

Hi Darren,

Thanks for posting back.

I'm glad to know you have resolved the problem. Regarding your new question, I think you want to make the background color of cells with 01/01/1900 values gray.

If not, please point it out and let us know.

If so, I suggest you try the following JSON code. This will display the background color of the cell in question as gray and the text color as black.

{

 "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

 "elmType": "div",

 "style": {

   "background-color": "=if(toLocaleDateString(@currentField) == '01/01/1900', 'grey', '')",

   "color": "=if(toLocaleDateString(@currentField) == '01/01/1900', 'black', if(@currentField <= @now, 'red', if(@currentField <= @now + 1209600000 && @currentField > @now, 'orange', 'green')))",

   "font-weight": "=if(@currentField <= @now, 'bold', if(@currentField <= @now + 315576000000 && @currentField > @now, 'bold', 'green'))",

   "font-size": "=if(@currentField <= @now, '14px', if(@currentField <= @now + 315576000000 && @currentField > @now, '14px', 'green'))"

 },

 "txtContent": "@currentField"

}

We look forward to your response. Thanks for your cooperation. 😊

Sincerely,

George | Microsoft Community Moderator

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2025-01-13T09:41:54+00:00

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json","elmType": "div","txtContent": "@currentField","style": {"color": "=if(toLocaleDateString(@currentField) == '01/01/1900', 'Grey', if(@currentField <= @now, 'red', if(@currentField <= @now + 1209600000 && @currentField > @now, 'orange', 'green')))","font-weight": "=if(@currentField <= @now, 'bold', if(@currentField <= @now + 315576000000 && @currentField > @now, 'bold', 'green'))","font-size": "=if(@currentField <= @now, '14px', if(@currentField <= @now + 315576000000 && @currentField > @now, '14px', 'green'))"}} Got it working with changing te date to 01/01/1900 instead of 1/1/1900

Was this answer helpful?

0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2025-01-09T16:20:15+00:00

    Colour code at present with that JSON provided

    {

     "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

     "elmType": "div",

     "txtContent": "@currentField",

     "style": {

       "color": "=if(toLocaleDateString(@currentField) == '1/1/1900', 'grey', if(@currentField <= @now, 'crimson', if(@currentField <= @now + 1209600000 && @currentField > @now, 'orange', 'green')))",

       "font-weight": "=if(@currentField <= @now, 'bold', if(@currentField <= @now + 315576000000 && @currentField > @now, 'bold', 'green'))",

       "font-size": "=if(@currentField <= @now, '14px', if(@currentField <= @now + 315576000000 && @currentField > @now, '14px', 'green'))"

     }

    }

    We look forward to your response. Thanks for your cooperation. 😊

    Sincerely,

    George | Microsoft Community Moderator 

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2025-01-09T16:10:29+00:00

    Thanks for the reply George

    Ive attempted the JSON but seems to stay as red

    Please see attached screenshots

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2025-01-09T15:41:34+00:00

    Hi Darren,

    Thanks for posting in the community. We are happy to help you.

    Per your description, I suggest you try the following JSON code. See if it works for you. If it doesn't work, I would like to know the date format on your end. Please provide an example date.

    {

     "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

     "elmType": "div",

     "txtContent": "@currentField",

     "style": {

       "color": "=if(toLocaleDateString(@currentField) == '1/1/1900', 'grey', if(@currentField <= @now, 'crimson', if(@currentField <= @now + 1209600000 && @currentField > @now, 'orange', 'green')))",

       "font-weight": "=if(@currentField <= @now, 'bold', if(@currentField <= @now + 315576000000 && @currentField > @now, 'bold', 'green'))",

       "font-size": "=if(@currentField <= @now, '14px', if(@currentField <= @now + 315576000000 && @currentField > @now, '14px', 'green'))"

     }

    }

    We look forward to your response. Thanks for your cooperation. 😊

    Sincerely,

    George | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments