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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Working Days In The Current Month

Status
Not open for further replies.

Hootie777

Programmer
Sep 5, 2002
4
GB
Example Of The Problem:

A Bonus Is Paid At A Monthly Rate But Only For Days Worked
If The Employee Is Off Sick Or On Holliday He Loses That Days Portion Of His Monthly Bonus.

I Know What Days He/She has Worked And I Know The Bonus Amount.

I Want The Number Of Working Days InThe Current Month To Be Displayed Automatically.

I Know Of The Function "Networkdays" but can't use it for this purpose.

Thanx

Hootie

"Don't Look A Gift Horse In The Mouth"
 
You can use this function to return the number of Workdays in a month if you are talking about Monday thur Friday as being the workdays. If you want to include Sunday or Saturday then you would have to adjust the If statement.
dteInput is just any date value.
Paul
Code:
Function WorkDaysInMonth(dteInput As Date) As Integer
    Dim intDays As Integer, workDays As Integer
    Dim i As Integer
    
    intDays = DateSerial(Year(dteInput), Month(dteInput) + 1, Day(dteInput)) _
        - DateSerial(Year(dteInput), Month(dteInput), Day(dteInput))
    
    For i = 1 To intDays
    If Weekday(Month(dteInput) & "/" & i & "/" & Year(dteInput)) = 1 Or Weekday(Month(dteInput) & "/" & i & "/" & Year(dteInput)) = 7 Then
    Else
    workDays = workDays + 1
    End If
    Next
   WorkDaysInMonth = workDays
     
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top