Forum Discussion

Edd_Keogh's avatar
Edd_Keogh
Copper Contributor
Aug 11, 2023

Conditional Formatting Dependant On Date

Hi all,   I have spent the last few hours trying anything I can find online to try and resolve this with no luck, hoping someone can help!   I want a date column to be green if date today onwards...
  • ganeshsanap's avatar
    Aug 11, 2023

    Edd_Keogh Use this JSON column formatting for your date column: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "background-color": "=if(Number(@currentField) == 0 , '', if(@currentField < addDays(@now, -7), 'red', if(@currentField < @now, 'yellow', 'green')))",
        "padding-left": "14px",
        "color": "=if(Number(@currentField) == 0, '', 'white')"
      }
    }

     

    You can also refer the list column values in JSON using the internal name of column like [$StartDate]. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online? 

     

    Also, here I have used Number(@currentField) == 0 to check date column is blank or not. You can find other ways to check if date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty

     

    Output

    You can adjust the conditions as per your requirements if needed.


    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.

Resources