Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate day

Status
Not open for further replies.

Twig

MIS
Joined
Sep 24, 2002
Messages
4
Location
US
I wonder is there any ways where I can count days but despite Saturday and Sunday.

for example...there will be to date
July 25, 2002 and July 31, 200
I want to calculate how many days used but ignore Saturday and Sunday....in this case, the total days used should be 4 days (excluding Saturday and Sunday)

Please if anyone can give me suggestions.

 
This will do it (if you need to woory about holidays in that period I have code to handle this as well, but it needs a seperate table with the holiday dates in it).

Requested code follows:

Public Function DiffWeekDays_TSB(datDay1 As Date, datDay2 As Date) As Long

' Comments : Returns the number of business days between two dates
' Weekend dates (Saturday and Sunday) are not counted.
' Parameters: datDay1 - first (earlier) date/time (subtracted from datDay2)
' datDay2 - second (later) date/time
' Returns : Number of whole business days between two dates
' (Returns negative days if datDay1 is after datDay2)

Dim lngWeekdays As Long

Dim StartDate As Date, EndDate As Date

lngWeekdays = 0
StartDate = Format(datDay1, "Short Date")
EndDate = Format(datDay2, "Short Date")

Do Until StartDate > EndDate
If WeekDay(StartDate) <> 1 And WeekDay(StartDate) <> 7 Then
lngWeekdays = lngWeekdays + 1
End If
StartDate = Format(DateAdd(&quot;d&quot;, 1, StartDate), &quot;Short Date&quot;)
Loop

DiffWeekDays_TSB = lngWeekdays

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top