Hi @Crystal D. Wood,
Thank you for posting in this community.
You can use the column formatting JSON below to calculate the difference in days between today and the deadline and modify the style of the columns. We use @now to get today's date dynamically, so we don't need to manually modify today's date.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if((floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24)))<0,'sp-css-backgroundColor-BgCoral sp-css-borderColor-CoralFont sp-css-color-CoralFont',if((floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24)))<=7,'sp-css-backgroundColor-BgPeach sp-css-borderColor-PeachFont sp-css-color-PeachFont',if((floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24)))<=30,'sp-css-backgroundColor-BgGold sp-css-color-GoldFont',if((floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24)))<=90,'sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont sp-css-color-MintGreenFont',if((floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24)))<=180,'sp-css-backgroundColor-BgCyan sp-css-color-CyanFont','sp-css-backgroundColor-BgLightGray sp-css-borderColor-LightGrayFont sp-css-color-LightGrayFont')))))"
},
"txtContent": "@currentField"
}
Here is my test result:
Our core formula for calculating days is floor((Number([$DeadLine]-Number(@now)))/(1000*60*60*24))
.
To break down the calculation into pieces:
- Number(…) will convert a date into a number in milliseconds.
- Number([$DeadLine]-Number(@now) will take DeadLine's date in milliseconds and subtract from today’s date in milliseconds.
- (10006060*24) will calculate duration of a day in milliseconds: 1000 milliseconds * 60 seconds * 60 minutes * 24 hours.
- floor((Number([$DeadLine]-Number(@now)))/(10006060*24)) will take the difference between dates, divide it by duration of a day, and round the final number down to a full number.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.