Forum Discussion

robrkhw's avatar
robrkhw
Copper Contributor
Mar 07, 2023
Solved

Formatting the date

Hi

 

I have a column called "Last Reviewed / Updated" which is a date field - i would like to highlight just the field red and have the text white and bold to indicate that 7 days has passed since the last review.

 

If the review was within 7 days the column should remain unformatted.

 

Could anyone assist with the JSON to do this please?

  • robrkhw Use this JSON column formatting for your date column: 

     

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

     

    Output


    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.

    For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

3 Replies

  • robrkhw Use this JSON column formatting for your date column: 

     

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

     

    Output


    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.

    For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

  • SvenSieverding's avatar
    SvenSieverding
    Bronze Contributor

    Hi robrkhw;


    this should work

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
        "elmType": "div",
    	"attributes": {
        "class": "=if(floor((Number(@currentField)-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))<-7,'ms-fontColor-red','')"
      },	
        "txtContent": "=@currentField"    
    }


    If the difference in Days between the current field and now is less that "-7" then add the class "ms-fontColor-red"

    Best Regards,
    Sven