SharePoint Online Date Calculation

%3CLINGO-SUB%20id%3D%22lingo-sub-118060%22%20slang%3D%22en-US%22%3ESharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118060%22%20slang%3D%22en-US%22%3E%3CP%3EI'd%20like%20to%20calculate%20the%20number%20of%20days%20between%20%5Btoday%5D%20and%20the%20due%20date%20in%20a%20SharePoint%20Online%20task%20list.%26nbsp%3B%20Not%20sure%20why%20this%20seems%20so%20difficult%20or%20why%20I%20can't%20readily%20find%20an%20answer%20online.%26nbsp%3B%20Any%20ideas%3F%26nbsp%3B%20Thanks%20so%20much%20ahead%20of%20time%20for%20your%20help.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-118060%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDate%20Calculations%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EToday%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-293910%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-293910%22%20slang%3D%22en-US%22%3E%3CP%3EWow%2C%20thank%20you%20for%20sharing%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29417%22%20target%3D%22_blank%22%3E%40Christophe%20Humbert%3C%2FA%3E.%20Now%20it%20looks%20really%20great%2C%20short%20and%20easy%20to%20read.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-293714%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-293714%22%20slang%3D%22en-US%22%3E%3CP%3EOh%20my%20gosh%2C%20Christophe!%26nbsp%3B%20Thanks%20so%20much%20for%20your%20help%20and%20answer!%26nbsp%3B%20Great%20to%20hear%20from%20you%20again.%26nbsp%3B%20You%20helped%20me%20on%20some%26nbsp%3B%20projects%20over%20three%20years%20ago!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-293666%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-293666%22%20slang%3D%22en-US%22%3E%3CP%3EAlthough%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F101888%22%20target%3D%22_blank%22%3E%40Pavel%20Sheludkov%3C%2FA%3E%26nbsp%3Balready%20provided%20an%20answer%2C%20I%20just%20wanted%20to%20mention%20that%20view%20and%20column%20formatting%20now%20accept%20formulas%20that%20significantly%20shorten%20the%20expression.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20this%20case%20you%20would%20just%20write%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%22%3D(Number(%5B%24DueDate%5D)-Number(%40now))%2F86400000%22%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-278606%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-278606%22%20slang%3D%22en-US%22%3E%3CP%3EAny%20insight%20on%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210118%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210118%22%20slang%3D%22en-US%22%3EGood%20to%20hear.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20was%20first%20trying%20to%20use%20the%20calculated%20column%20but%20then%20realised%20that%20JSON%20formatting%20is%20much%20easier%20approach.%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%2C%20if%20you%20haven't%20installed%20this%20amasing%20tool%20for%20working%20with%20JSON%20formating%20yet%2C%20do%20it.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fthechriskent.com%2F2017%2F12%2F21%2Fcolumn-formatting-client-side-web-part-column-formatter%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fthechriskent.com%2F2017%2F12%2F21%2Fcolumn-formatting-client-side-web-part-column-formatter%2F%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210115%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210115%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20very%20much%20for%20this%20and%20especially%20your%20explanation.%26nbsp%3B%20I%20did%20some%20quick%20searching%20but%20was%20not%20able%20to%20quickly%20ascertain%20why%20it%20is%20returning%20NAN%20even%20though%20my%20column%20is%20formatted%20as%20a%20number.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210109%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210109%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20are%20using%20the%20New%20experience%20interface%20than%20you%20can%20achieve%26nbsp%3Bit%20with%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fcolumn-formatting%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EJSON%20column%20formatting.%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20the%20example%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7B%3CBR%20%2F%3E%22%24schema%22%3A%20%22%3CA%20href%3D%22http%3A%2F%2Fcolumnformatting.sharepointpnp.com%2FcolumnFormattingSchema.json%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcolumnformatting.sharepointpnp.com%2FcolumnFormattingSchema.json%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22elmType%22%3A%20%22div%22%2C%3CBR%20%2F%3E%22txtContent%22%3A%20%7B%3CBR%20%2F%3E%22operator%22%3A%20%22%2F%22%2C%3CBR%20%2F%3E%22operands%22%3A%20%5B%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22operator%22%3A%20%22-%22%2C%3CBR%20%2F%3E%22operands%22%3A%20%5B%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22operator%22%3A%20%22Number()%22%2C%3CBR%20%2F%3E%22operands%22%3A%20%5B%3CBR%20%2F%3E%22%40now%22%3CBR%20%2F%3E%5D%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22operator%22%3A%20%22Number()%22%2C%3CBR%20%2F%3E%22operands%22%3A%20%5B%3CBR%20%2F%3E%22%5B%24DueDate%5D%22%3CBR%20%2F%3E%5D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%5D%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E86400000%3CBR%20%2F%3E%5D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20see%20in%20the%20example%20that%20it%20converts%20%22%40now%22%20and%20%22%5B%24DueDate%5D%22%20into%20numbers%2C%20then%20subtract%20them.%20Finally%2C%20the%20subtraction%20result%20is%20divided%20by%26nbsp%3B%3CSPAN%3E86400000%20-%20the%20number%20of%20milliseconds%20in%20a%20day.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119296%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119296%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%20Matt...may%20not%20be%20beautiful%2C%20but%20that%20will%20work!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118647%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118647%22%20slang%3D%22en-US%22%3E%3CP%3E%22How%20many%20days%20left%20until%20this%20item%20is%20due%3F%22%26nbsp%3B%20For%20now%2C%20I'm%20looking%20for%20all%20days%20since%20elimininating%20weekends%20may%20be%20a%20challenge%20for%20now.%26nbsp%3B%20%26nbsp%3BI%20have%20a%20start%20date%20and%20a%20due%20date.%26nbsp%3B%20How%20many%20days%20between%20those%20two%3F%26nbsp%3B%20Thanks!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118580%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118580%22%20slang%3D%22en-US%22%3EWhat%20are%20you%20trying%20to%20accomplish%20with%20the%20calculation%3F%20That%20I%20would%20like%20more%20to%20know%20%3A)%3C%2Fimg%3E%3CBR%20%2F%3EKind%20regards%2C%20John%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118164%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118164%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20problem%20is%20SharePoint%20Online%20treats%20that%20as%20a%20calculation%2C%20and%20calculations%20are%20only%20refreshed%20when%20the%20item%20is%20modified%20in%20any%20way%20(at%20least%2C%20out%20of%20the%20box).%20The%20only%20way%20I%20could%20find%20to%20force%20the%20date%20to%20recalculate%20was%20to%20create%20a%20loop%20in%20SharePoint%20Designer%20or%20Flow%20to%20overwrite%20something%20in%20an%20item%20with%20its%20current%20value%20until%20due%20date%20%3D%20today%2C%20which%20technically%20changes%20nothing%20about%20the%20item%20while%20still%20counting%20as%20a%20modification%2C%20resulting%20in%20a%20refresh%20of%20a%20date%20difference%20calculation.%20It's%20an%20expensive%20workaround%2C%20especially%20on%20large%20lists%20with%20lots%20of%20due%20date%20items%2C%20but%20it's%20the%20only%20non-custom%20way%20I%20know%20of%20to%20manage%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-412680%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-412680%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29417%22%20target%3D%22_blank%22%3E%40Christophe%20Humbert%3C%2FA%3E%26nbsp%3Bis%20there%20any%20was%20to%20get%20the%20correct%20integer%20value%20of%20that%2015%26nbsp%3Bdecimal%20number%20that%20is%20returned%3F%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29417%22%20target%3D%22_blank%22%3E%40Christophe%20Humbert%3C%2FA%3E%26nbsp%3Bwrote%3A%3CBR%20%2F%3E%3CP%3EIn%20this%20case%20you%20would%20just%20write%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%22%3D(Number(%5B%24DueDate%5D)-Number(%40now))%2F86400000%22%3C%2FSPAN%3E%3C%2FP%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-720857%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720857%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F310592%22%20target%3D%22_blank%22%3E%40Visuary%3C%2FA%3E%26nbsp%3BDid%20you%20ever%20figure%20out%20how%20to%20display%20the%20value%20as%20an%20interger%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1732391%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20Calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1732391%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F101888%22%20target%3D%22_blank%22%3E%40Pavel%20Sheludkov%3C%2FA%3E%26nbsp%3Bthank%20you%20for%20sharing%20this%20format.%20this%20works%20on%20my%20sharepoint%20list%20column.%20however%2C%20do%20you%20know%20how%20to%20remove%20the%20decimal%20points%20and%20just%20make%20it%20a%20round%20number%20of%20days%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Abbyamante_0-1601503164864.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F223158i36E6095EBC850F7D%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Abbyamante_0-1601503164864.png%22%20alt%3D%22Abbyamante_0-1601503164864.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I'd like to calculate the number of days between [today] and the due date in a SharePoint Online task list.  Not sure why this seems so difficult or why I can't readily find an answer online.  Any ideas?  Thanks so much ahead of time for your help. 

14 Replies
Highlighted

The problem is SharePoint Online treats that as a calculation, and calculations are only refreshed when the item is modified in any way (at least, out of the box). The only way I could find to force the date to recalculate was to create a loop in SharePoint Designer or Flow to overwrite something in an item with its current value until due date = today, which technically changes nothing about the item while still counting as a modification, resulting in a refresh of a date difference calculation. It's an expensive workaround, especially on large lists with lots of due date items, but it's the only non-custom way I know of to manage this.

Highlighted
What are you trying to accomplish with the calculation? That I would like more to know :)
Kind regards, John
Highlighted

"How many days left until this item is due?"  For now, I'm looking for all days since elimininating weekends may be a challenge for now.   I have a start date and a due date.  How many days between those two?  Thanks!  

Highlighted

Thanks, Matt...may not be beautiful, but that will work!  

Highlighted

If you are using the New experience interface than you can achieve it with JSON column formatting.

 

Here is the example: 

 

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "div",
"txtContent": {
"operator": "/",
"operands": [
{
"operator": "-",
"operands": [
{
"operator": "Number()",
"operands": [
"@now"
]
},
{
"operator": "Number()",
"operands": [
"[$DueDate]"
]
}
]
},
86400000
]
}
}

 

You can see in the example that it converts "@now" and "[$DueDate]" into numbers, then subtract them. Finally, the subtraction result is divided by 86400000 - the number of milliseconds in a day.

 

Cheers

 

Highlighted

Thanks very much for this and especially your explanation.  I did some quick searching but was not able to quickly ascertain why it is returning NAN even though my column is formatted as a number.  

Highlighted
Good to hear.

I was first trying to use the calculated column but then realised that JSON formatting is much easier approach.

Also, if you haven't installed this amasing tool for working with JSON formating yet, do it.
https://thechriskent.com/2017/12/21/column-formatting-client-side-web-part-column-formatter/
Highlighted

Any insight on this?

Highlighted

Although @Pavel Sheludkov already provided an answer, I just wanted to mention that view and column formatting now accept formulas that significantly shorten the expression.

 

In this case you would just write:

"=(Number([$DueDate])-Number(@now))/86400000"

Highlighted

Oh my gosh, Christophe!  Thanks so much for your help and answer!  Great to hear from you again.  You helped me on some  projects over three years ago!  

Highlighted

Wow, thank you for sharing @Christophe Humbert. Now it looks really great, short and easy to read. 

Highlighted

@Christophe Humbert is there any was to get the correct integer value of that 15 decimal number that is returned? 


@Christophe Humbert wrote:

In this case you would just write:

"=(Number([$DueDate])-Number(@now))/86400000"




Highlighted

@Visuary Did you ever figure out how to display the value as an interger?

Highlighted

@Pavel Sheludkov thank you for sharing this format. this works on my sharepoint list column. however, do you know how to remove the decimal points and just make it a round number of days?

 

Abbyamante_0-1601503164864.png