Add and subtract the differance between two dates

Neokey

New Member
Joined
Oct 14, 2005
Messages
10
Hi all,

I have a workbook where I need to show the difference between two dates in months and days, where one date can be earlier in column A and B the date can be later in column A and B.

ABA & B Diff
03/08/202314/06/202410M 11D
04/05/202414/12/2023
#NUM!​
22/11/202308/03/20243M 15D
25/01/202424/11/2023
#NUM!​
04/08/202314/12/20234M 10D
11/01/202430/05/20244M 19D
10/01/202430/05/20244M 20D
24/01/202407/06/20244M 14D
16/02/202426/06/20244M 10D
24/02/202427/10/2023
#NUM!​

I need to show negative months and days where B is earlier than A. can anyone help please.

Thank you
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Something like this:

Code:
=IFERROR((DATEDIF(0,D2,"y") & " years " & DATEDIF(0,D2,"ym") & " months "& DATEDIF(0,D2,"md") &" days"), 
"- " & (DATEDIF(0,-D2,"y") &" years " & DATEDIF(0,-D2,"ym") & " months " & DATEDIF(0,-D2,"md") & " days"))
 
Upvote 0
I thought I had a good solution with DATEDIF, but it seems to miscalculate around leap day 2024. Does anyone know why this happens?
Book1
ABCDEF
10StartEndMonth DiffDay DiffConcatCheck
112023-Aug-32024-Jun-14101110M 11D2024-Jun-14
122024-May-42023-Dec-14-4-20-4M 20D2023-Dec-15
132023-Nov-222024-Mar-83153M 15D2024-Mar-8
142024-Jan-252023-Nov-24-2-1-2M 1D2023-Nov-24
152023-Aug-42023-Dec-144104M 10D2023-Dec-14
162024-Jan-112024-May-304194M 19D2024-May-30
172024-Jan-102024-May-304204M 20D2024-May-30
182024-Jan-242024-Jun-74144M 14D2024-Jun-7
192024-Feb-162024-Jun-264104M 10D2024-Jun-26
202024-Feb-242023-Oct-27-3-28-3M 28D2023-Oct-27
212024-Mar-12023-Dec-14-2-16-2M 16D2023-Dec-16
222024-Feb-12023-Dec-14-1-18-1M 18D2023-Dec-14
232024-Feb-292023-Dec-14-2-15-2M 15D2023-Dec-14
Sheet1
Cell Formulas
RangeFormula
C11:C23C11=IFERROR(DATEDIF(A11,B11,"m"),-1*DATEDIF(B11,A11,"m"))
D11:D23D11=IFERROR(DATEDIF(DATE(YEAR(A11),MONTH(A11)+C11,DAY(A11)),B11,"d"),-1*DATEDIF(DATE(YEAR(B11),MONTH(B11)-C11,DAY(B11)),A11,"d"))
E11:E23E11=C11&"M "&ABS(D11)&"D"
F11:F23F11=DATE(YEAR(A11),MONTH(A11)+C11,DAY(A11)+D11)


Doug
 
Upvote 0
Yeah, for sure there is something off with the DATEDIF function and leap years. I do not fully comprehend it, but here are some references.

A quote from that page..."Since Date1 is not a leap year, the date 29-Feb is not counted."

Where I found a link to that:

Some strange results related to leap year calculations.
Book1
ABCDEF
252024-Mar-22023-Dec-30-2-1-2M 1D2024-Jan-1
262024-Mar-22023-Dec-31-20-2M 0D2024-Jan-2
272024-Mar-22024-Jan-1-2-1-2M 1D2024-Jan-1
Sheet1
Cell Formulas
RangeFormula
C25:C27C25=IFERROR(DATEDIF(A25,B25,"m"),-1*DATEDIF(B25,A25,"m"))
D25:D27D25=IFERROR(DATEDIF(DATE(YEAR(A25),MONTH(A25)+C25,DAY(A25)),B25,"d"),-1*DATEDIF(DATE(YEAR(B25),MONTH(B25)-C25,DAY(B25)),A25,"d"))
E25:E27E25=C25&"M "&ABS(D25)&"D"
F25:F27F25=DATE(YEAR(A25),MONTH(A25)+C25,DAY(A25)+D25)
 
Upvote 0
If you can work with the number of days between dates, this will work...
Book1
ABC
302024-Mar-22023-Dec-30-63
312024-Mar-22023-Dec-31-62
322024-Mar-22024-Jan-1-61
Sheet1
Cell Formulas
RangeFormula
C30:C32C30=B30-A30
 
Upvote 0
Dates Time.xlsm
ABCD
1StartEndMonth DiffDays
23-Aug-2314-Jun-241011
34-May-2414-Dec-23420
422-Nov-238-Mar-24315
525-Jan-2424-Nov-2321
64-Aug-2314-Dec-23410
711-Jan-2430-May-24419
810-Jan-2430-May-24420
924-Jan-247-Jun-24414
1016-Feb-2426-Jun-24410
1124-Feb-2427-Oct-23328
121-Mar-2414-Dec-23216
131-Feb-2414-Dec-23118
1429-Feb-2414-Dec-23215
15
3g
Cell Formulas
RangeFormula
C2:C14C2=DATEDIF(MIN(A2:B2),MAX(A2:B2),"m")
D2:D14D2=ABS(B2-A2)-(EDATE(MIN(A2:B2),C2)-MIN(A2:B2))
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,066
Members
449,090
Latest member
fragment

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