DateDiff to return positive and negative numbers

marcus314

New Member
Joined
Jun 4, 2014
Messages
20
Hi,

I searched for a solution, but couldn't find one that fit my specific needs, so I thought I'd turn to this great forum!

I have a date in cell M2 and am wishing to calculate the date difference in days. The formula I created works great when there is a positive difference. However, for anything < 0, the cell is blank. I'm essentially trying to show both positive and negative values.

Excel Formula:
=IFERROR(DATEDIF(TODAY(),M2,"d"),"")

Any ideas how to adjust this formula to achieve this?

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
maybe
Excel Formula:
=IFERROR(DATEDIF(TODAY(),M2,"d"),-DATEDIF(M2,TODAY(),"d"))
define which part should show negative or positive value
 
Last edited by a moderator:
Upvote 0
Solution
Here's one way:
Excel Formula:
=IFERROR(DATEDIF(TODAY(),M2,"d"),IFERROR(-DATEDIF(M2,TODAY(),"d"),""))

DATEDIF requires the first date argument to be less than or equal to the 2nd date argument.
 
Last edited by a moderator:
Upvote 0
How about
Excel Formula:
=M2-TODAY()
and format the cell as general.
 
Upvote 0
T202002a.xlsm
KLM
7
8229-Dec-2031-Dec-20
9229-Dec-2031-Dec-20
102231-Dec-20
1189-Dec-201-Dec-20
1281-Dec-20
1389-Dec-201-Dec-20
1481-Dec-209-Dec-20
1581-Dec-20
6e
Cell Formulas
RangeFormula
L13,L11,L8:L9L8=TODAY()
K8K8=DATEDIF(L8,M8,"d")
K9K9=DATEDIF(MIN(L9,M9),MAX(L9,M9),"d")
K10:K12K10=DATEDIF(MIN(TODAY(),M10),MAX(TODAY(),M10),"d")
K13:K14K13=ABS(L13-M13)
K15K15=ABS(TODAY()-M15)
 
Upvote 0
Thanks everyone. Every solution worked great. I appreciate the amazing community here for all of the help!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
another option

ResultExample
DateDaysDateTodayDays
05/12/2020-505/12/202010/12/2020-5
20/12/2020920/12/202010/12/20209


Power Query:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    DTLN = Table.AddColumn(Source, "Today", each DateTime.LocalNow()),
    Days = Table.AddColumn(DTLN, "Days", each Duration.Days([Date] - [Today]), Int64.Type),
    TSC = Table.SelectColumns(Days,{"Days"})
in
    TSC
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,665
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top