Jan 10 2023 04:26 PM
Hello!
I'm using a SharePoint 365 list as an action tracker. My list contains the due date. I would like to add a column that contains a count of days remaining to the due date.
I tried the datedif function together with 'TODAY', but it does not work. I guess I need to have an additional column with today's date to use this one? Was hoping to create it using workflows but these were retired in SharePoint 365. Is there a way to do it differently?
Would much appreciate your help.
Jan 10 2023 11:28 PM - edited Jan 10 2023 11:29 PM
@kobi1991
You could apply JSON Formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=floor((Number(@currentField)-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))+' day(s) remaining'"
}
Best Regards,
Sven
Jan 11 2023 02:55 AM
Thank you, Sven! Apologies but I'm completely new at this - could you please explain where in the code I should put my 'due date' column?
Karolina
Jan 11 2023 03:05 AM
SolutionHi @kobi1991 ,
sure. This is SharePoint Json list formatting code that formats a column.
https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting
Got to you SharePoint View, select the header of your "Due Date" column and select "Column Settings->Format this Column"
Copy the Json Code here
You don't have to change the formula, as "@currentField" references to the selected Column.
Best Regards,
Sven
Jan 11 2023 08:20 AM
Jan 11 2023 08:30 AM
Hi @kobi1991
You could create a calculated column "Countdown" of type "Date" with the formula
=[Due Date]
and then apply the formatting there.
Then you have two columns with the same value, but one is displaying the date and the other one is displaying the countdown.
Best Regards,
Sven
Jun 21 2023 09:56 PM
Hi @SvenSieverding,
I have a question about your json code, i have tried to apply the code into my list but all the dates that have past due displays for example "-29 days", is there any code that could make all the dates that have past due displays "0 days"
Thanks
Best Regards,
Faric
Jun 21 2023 11:12 PM
Hi @faric1311,
in that case you can just wrap it into an if clause.
This displays the remaining days, if the calculated value is larger than 0 and "no days remaining" if that value is below or equal 0.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(floor((Number(@currentField)-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))>0,floor((Number(@currentField)-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))+' day(s) remaining','no days remaining')"
}
Best Regards,
Sven
Aug 15 2023 01:43 PM
Aug 15 2023 10:41 PM
Hi @Chawoo,
sure.
@currentField
refers to the column where the format is applied on. But you can refer other columns by their internal Name.
Given you have the column "Other Date Column" then you reference that as "[$OtherDateColumn]", so the formula becomes this
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(floor((Number([$OtherDateColumn])-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))>0,floor((Number([$OtherDateColumn])-Number(Date((getMonth(@now)+1)+'.'+getDate(@now)+'.'+getYear(@now))))/(60*60*24*1000))+' day(s) remaining','no days remaining')"
}
Now apply that to your other (Countdown) column.
Best Regards,
Sven
Aug 29 2023 12:56 PM
@SvenSieverding Is it possible to leverage this same approach but list days and hours, as opposed to just days? Appreciate your advice.
Jan 11 2023 03:05 AM
SolutionHi @kobi1991 ,
sure. This is SharePoint Json list formatting code that formats a column.
https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting
Got to you SharePoint View, select the header of your "Due Date" column and select "Column Settings->Format this Column"
Copy the Json Code here
You don't have to change the formula, as "@currentField" references to the selected Column.
Best Regards,
Sven