>>The following DateDiff function does not give the correct result in
>>certain
cases.
VB Datediff uses different rules than the worksheet function. It counts the
number of times the month changes. 8/31 to 9/1 is one month because the
month changes once.
You might see if this gives the answer you'd get with the worksheet
function:
DateDiff("m", StartDate, EndDate) - IIf(Day(StartDate) > Day(EndDate), 1, 0)
--
Jim
"Basharat Javaid" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| The following DateDiff function does not give the correct result in
certain
| cases. It counts the final month in which Day(EndDate) occurs even if the
| Day(StartDate)>Day(EndDate).
| E.g.. for StartDate= 08/19/51 & EndDate= 09/01/2016 it gives 781 months
| which includes the month of 09/20/16!
| Whereas the worksheet function DateDif ("m", StartDate,EndDate), gives the
| correct answer.
|
| Furthermore, Application.DateDif ("m", StartDate,EndDate) does not work in
| the VBA module.
| --
| Hoa Nguyen
|
|
|