3

As you can see in the picture, I have a date type field and I would like this field only to be displayed in orange when the month of the date is equal to the month of the current date but I don't not see how to do it.

Anyone have any idea for this?

=

3

Use either of below JSON codes on your date column as per your requirements:

Based on Month only:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(getMonth(@currentField) == getMonth(@now), 'Orange', 'initial')",
    "padding-left": "10px"
  }
}

Output:

enter image description here

Based on Month & Year:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(getMonth(@currentField) == getMonth(@now) && getYear(@currentField) == getYear(@now), 'Orange', 'initial')",
    "padding-left": "10px"
  }
}

Output:

enter image description here


Make sure you are adding this JSON on correct date & time column.

Documentation: Use column formatting to customize SharePoint


Update:

Follow below steps to add JSON code to column formatting:

  1. Go to SharePoint list

  2. Click on column header/name

  3. Select Column settings & then Format this column

    enter image description here

  4. Make sure your date column is selected under Choose Column dropdown

  5. Add JSON at the last textbox on right side panel (Advanced mode)

  6. Click Save

enter image description here

2

Try this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(getMonth([$DateField])==getMonth(@now), 'Orange', '')",
    "color": "black",
    "font-size": "1.5em",
    "justify-content": "center"
  }
}

More info on JSON column formatting can be found here

enter image description here

2
  • it does not work.. – Alexandre Picque Apr 21 at 16:10
  • 1
    Have you updated [$DateField] to your field name? Or to @currentField? – Matiur Rahman Apr 21 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.