DateDif Question

rcolving

Board Regular
Joined
May 23, 2002
Messages
124
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
Platform
  1. Windows
I have a spread sheet with two dates, I am using the following formula which works great if both cells are populated, but if one is not populated with a date I get #NUM!. If one of the cells is not populated I want the cell to be blank. =DATEDIF(D3,E3,"y") & " Years, " & DATEDIF(D3,E3,"ym") & " Months, " & DATEDIF(D3,E3,"md") & " Days"
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You could wrap your formula in an IFERROR function...

=IFERROR(DATEDIF(D3,E3,"y") & " Years, " & DATEDIF(D3,E3,"ym") & " Months, " & DATEDIF(D3,E3,"md") & " Days","")
 
Upvote 0
If it comes up as an error,

Excel Formula:
=IFERROR(DATEDIF(E3,D3,"y") & " Years, " & DATEDIF(E3,D3,"ym") & " Months, " & DATEDIF(E3,D3,"md") & " Days","")
 
Upvote 0
Another option
Excel Formula:
=IF(OR(D3="",E3=""),"",DATEDIF(D3,E3,"y") & " Years, " & DATEDIF(D3,E3,"ym") & " Months, " & DATEDIF(D3,E3,"md") & " Days")
 
Upvote 0
Ensure the order of the dates is correct.

T202010a.xlsm
DEF
31-Mar-201-Jan-200 Years, 2 Months, 0 Days
4
1c
Cell Formulas
RangeFormula
F3F3=IF(OR(D3="",E3=""),"",DATEDIF(E3,D3,"y") & " Years, " & DATEDIF(E3,D3,"ym") & " Months, " & DATEDIF(E3,D3,"md") & " Days")
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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