|
|
|
Click here to copy the following block |
Function BusinessDateDiff(ByVal StartDate As Date, ByVal EndDate As Date, _ Optional ByVal SaturdayIsHoliday As Boolean = True) As Long Dim incr As Date StartDate = Int(StartDate) EndDate = Int(EndDate) If StartDate < EndDate Then incr = 1 Else incr = -1 Do Until StartDate = EndDate StartDate = StartDate + incr If Weekday(StartDate) <> vbSunday And (Weekday(StartDate) <> vbSaturday _ Or Not SaturdayIsHoliday) Then BusinessDateDiff = BusinessDateDiff + incr End If Loop End Function
Public Function BusinessDateDiff(ByVal StartDate As Date, ByVal EndDate As Date, _ Optional ByVal SaturdayIsHoliday As Boolean = True) As Long Dim nDow1 As Integer, nDow2 As Integer nDow1 = Weekday(StartDate, vbSunday) nDow2 = Weekday(EndDate, vbSunday) If SaturdayIsHoliday Then BusinessDateDiff = DateDiff("ww", StartDate, EndDate, _ vbSunday) * 5 - nDow1 + nDow2 - IIf(nDow2 = 7, 1, 0) + IIf(nDow1 = 7, 1, _ 0) Else BusinessDateDiff = DateDiff("ww", StartDate, EndDate, _ vbSunday) * 6 - nDow1 + nDow2 End If End Function
Private Declare Function GetTickCount Lib "kernel32" () As Long Public Function TimeTest() Dim nx As Integer, t1 As Single, t2 As Single Dim nDays As Integer t1 = GetTickCount() For nx = 1 To 10000 nDays = BusinessDateDiff(#1/1/2002#, #12/31/2002#, True) Next nx t2 = GetTickCount() Debug.Print "Test Complete: " & t2 - t1 & " milliseconds" End Function
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|