PC Review


Reply
Thread Tools Rate Thread

DateDiff ("m", StartDate,EndDate)

 
 
Basharat Javaid
Guest
Posts: n/a
 
      23rd Jul 2007
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


 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      23rd Jul 2007
>>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
|
|


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
startdate / enddate sum nologo Microsoft C# .NET 5 28th Feb 2008 11:32 AM
Startdate, Enddate louonline Microsoft Access Forms 2 10th Apr 2006 01:53 PM
[startdate]<="date"<=[enddate] Why doesn't this work in criteria. =?Utf-8?B?RWhhbmRhdTI=?= Microsoft Access 5 31st Mar 2005 12:04 PM
where DATE is BETWEEN startdate and enddate...how? Nathon Jones Microsoft Access 8 8th Mar 2005 01:37 PM
StartDate, EndDate AHopper Microsoft Access Form Coding 3 23rd Jan 2004 04:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 AM.