Hi all
I have the folowing to calculate the Number of weeks between two dates.
The OpenDate= Nov-1-12 and closingDate= Nov-29-12.
When Executing the the NumberOfWeeks=3
If I go to the calander 4 weeks why is the NumberOfWeeks=3

``````NumberOfWeeks = DateDiff(DateInterval.Weekday, OpenDate, ClosingDate)
``````

It's because of the way `Datediff` treats week calculations there's a pretty good example and explanation here.

## All 3 Replies

It's because of the way `Datediff` treats week calculations there's a pretty good example and explanation here.

With the link you provided and other Google searches I Created a Function that seams to work.

`````` Private Function GetBusinessWeeks(ByVal Date1 As Date, ByVal Date2 As Date) As Long

Dim days As Integer
Dim weeks As Integer
days = DateDiff(DateInterval.Day, Date1, Date2) + 1
Weeks = Days \ 7
Days = Days Mod 7
If Days > 0 Then
If date1.DayOfWeek = DayOfWeek.Sunday Or date2.DayOfWeek = DayOfWeek.Saturday Then
days = days - 1
ElseIf date2.DayOfWeek < date1.DayOfWeek Then
days = days - 2
End If
End If
Dim Weekes As Long = (weeks * 5 + days) / 5
Return Weekes
End Function
``````

Hi Viper,