Display duration 1yr 8 mo 15 days

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
The formula dateif allows me to create a formula to what I'm seeking, but in VBA dateiff doesnt really do the trick. In VBA, can someone assist me with a code that will allow me to display what I'm seeking.

i.e. 1yr 8 mo 15 days

Thank you kindly
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello,

Your question is not very precise ...

What are you currently using ???

In VBA, have you tested DATEDIFF() ...

Code:
[COLOR=#333333]=DATEDIFF([/COLOR][COLOR=#333333]"Y",[/COLOR][COLOR=#333333]LowerDate,UpperDate) &" Years "& DATEDIFF([/COLOR][COLOR=#333333]"YM",[/COLOR][COLOR=#333333]LowerDate,UpperDate) &" Months and " & DATEDIFF([/COLOR][COLOR=#333333]"MD",[/COLOR][COLOR=#333333]LowerDate,UpperDate)&" Days"[/COLOR]

See explanation : http://www.excelfunctions.net/vba-datediff-function.html

Hope this will help
 
Last edited:
Upvote 0
Yes...I have tried datediff, however, when using datediff to determine Years Months Days between 01/01/200 & 02/15/2005, I would get

5 years (Fine)
61 months (incorrect), I want to display 1 month
1858 days (incorrect) I want to display 14 days

The display I want to see in this scenario 5 Yrs 1 Mo 14 Days

I would need this in VBA as I am using a Userform


Hello,

Your question is not very precise ...

What are you currently using ???

In VBA, have you tried DATEDIFF() ...

Code:
[COLOR=#333333]=DATEDIFF(LowerDate,UpperDate,"Y") &" Years "& DATEDIFF(LowerDate,UpperDate,"YM") &" Months and " & DATEDIFF(LowerDate,UpperDate,"MD")&" Days"[/COLOR]

See explanation : http://www.excelfunctions.net/vba-datediff-function.html

Hope this will help
 
Last edited:
Upvote 0
Hello again,

Before getting into the DATEDIFF issue, since you are using a UserForm ... most probably both your dates are located in textboxes ...which means you are dealing with Strings and NOT actual DATES ...

Have you tried to use CDate in order to convert your text strings into numeric values ...???

HTH
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

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