M
Max
Hello,
I have an iif statement that calculates the # of working
days between two dates. Problem is that the return number
is in increments of 5. If # is within 1st week return = 0,
second week, return = 5, third week, return = 10 and so
forth. If begin date is Friday the 9, and end date is
Tuesay, the 13th, total # of days would be 2 (even 1 day -
for Monday would be acceptable)
IIF statement and module are below: Any ideas?
Thanks
Max
=(IIf(IsNull([From Gruen]),(Work_Days(Date(),[To Gruen])*-
1),Work_Days([To Gruen],[From Gruen])))
'*********** Code Start **************
Function Work_Days(BegDate As Variant, EndDate As Variant)
As Integer
'Note that this function does not account for holidays.
Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer
BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
WholeWeeks = DateDiff("w", BegDate, EndDate)
DateCnt = DateAdd("ww", WholeWeeks, BegDate)
EndDays = 0
Do While DateCnt < EndDate
If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat"
Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = WholeWeeks * 5 + EndDays
End Function
'*********** Code End **************
I have an iif statement that calculates the # of working
days between two dates. Problem is that the return number
is in increments of 5. If # is within 1st week return = 0,
second week, return = 5, third week, return = 10 and so
forth. If begin date is Friday the 9, and end date is
Tuesay, the 13th, total # of days would be 2 (even 1 day -
for Monday would be acceptable)
IIF statement and module are below: Any ideas?
Thanks
Max
=(IIf(IsNull([From Gruen]),(Work_Days(Date(),[To Gruen])*-
1),Work_Days([To Gruen],[From Gruen])))
'*********** Code Start **************
Function Work_Days(BegDate As Variant, EndDate As Variant)
As Integer
'Note that this function does not account for holidays.
Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer
BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
WholeWeeks = DateDiff("w", BegDate, EndDate)
DateCnt = DateAdd("ww", WholeWeeks, BegDate)
EndDays = 0
Do While DateCnt < EndDate
If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat"
Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = WholeWeeks * 5 + EndDays
End Function
'*********** Code End **************