DateDiff not working
-
Wednesday, August 15, 2007 6:11 PM
I have code that uses the DateDiff function
Private startDate As Date Private endDate As DatestartDate = DateTimeStart.Value
endDate = DateTimeEnd.Value
Label1.Text = "The DateDiff Value = " & Microsoft.VisualBasic.DateDiff(DateInterval.Day, startDate, endDate)
if I use the values of 8/15/2007 for StartDate and 8/15/2008 for endDate it returns 365.
It should be 366 for Leap Year
I do not see a problem in the code itself
I am using .net 2003 version
Is there a technical document on this problem?
All Replies
-
Wednesday, August 15, 2007 6:25 PM
This may not be the answer you are looking for, but can you use the "IsLeapYear" property to do your own validation of the date range?
If Date.IsLeapYear(startDate.Year) Or Date.IsLeapYear(endDate.Year) Then'Make the appropriate calibrations.
End If -
Friday, August 17, 2007 8:22 PMModerator
Scott,
I'm not aware of any known problems in this area. I tried this code - "Msgbox DateDiff(DateInterval.Day, #8/15/2007#, #8/15/2008#)" and I always got 366. I tried the following platforms:
VB.Net 2003 on Win2k3
VB.Net 2005 on Vista
VB 2008 Beta2 on Vista
On the machine where this error occurs, what do you get when you run this code:
MsgBox (System.Globalization.CultureInfo.CurrentCulture.Calendar.GetDaysInYear(2008))
Hope this helps narrow down your problem,
Adam
Visual Basic Team

