DateDiff ("m", StartDate,EndDate)

B

Basharat Javaid

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.
 
J

Jim Rech

The following DateDiff function does not give the correct result incases.

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
| 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
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top