[AccessD] Finding weekdays within a date range

Klos, Susan Susan.Klos at fldoe.org
Fri Sep 16 10:49:26 CDT 2005


I have actually been able to find the weekdays.  However, I need to set
some parameters and I can't seem to do that.  I borrowed the following
code from someone's web site.   It works perfectly for some of what I
need. 

Public Function WorkingDays(StartDate As Date, EndDate As Date) As
Integer

'....................................................................

' Name:     WorkingDays

' Inputs:   StartDate As Date

'   EndDate As Date

' Returns: Integer

' Author: Arvin Meyer

' Date:     February 19, 1997

' Comment: Accepts two dates and returns the number of weekdays between
them

' Note that this function does not account for holidays.

'....................................................................

On Error GoTo Err_WorkingDays

 

Dim intCount As Integer

 

'StartDate = StartDate + 1

'If you want to count the day of StartDate as the 1st day

'Comment out the line above

 

intCount = 0

Do While StartDate <= EndDate

'Make the above < and not <= to not count the EndDate

 

Select Case Weekday(StartDate)

Case Is = 1, 7

intCount = intCount

Case Is = 2, 3, 4, 5, 6

intCount = intCount + 1

End Select

StartDate = StartDate + 1

Loop

WorkingDays = intCount

 

Exit_WorkingDays:

Exit Function

 

Err_WorkingDays:

Select Case Err

 

Case Else

MsgBox Err.Description

Resume Exit_WorkingDays

End Select

 

End Function

 

I need to be able to modify this to find the weekdays under the
following criteria

1) if the inServiceBegin is after FCATWeek (a single date) then exit the
function.

2) if the inServiceBegin is before SchoolStart (a single date) then use
SchoolStart and the startdate.

3) if the inServiceEnd is after FCATWeek then use FCATWeek as the
enddate.

4) if the inServiceBegin is not null but the inServiceEnd is null
(inservice is only one day long) then 1.

5) if the inServiceBegin and inServiceEnd are before SchoolStart then
exit the function.

 

I think I have considered all the possibilities.  I am trying to
calculate how many weekdays fall within the range of inservice days and
these must fall on or after the start of school and on or before the
students take the test (FCATWeek).  I can use whatever help you can give
me.  Thanks.

Susan Klos

Senior Database Analyst

Evaluation and Reporting

Florida Department of Education

850-245-0708 

sc 205-0708

 




More information about the AccessD mailing list