Day of week

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to eliminate weekends from a query. I am using DateDiff and if a
weekend overlaps, I want it to basically subtract 2 from the difference
between the two dates. Is this possible?
 
I'd write a WeekdayDiff function something like:

Public Function WeekdayDiff(StartDate As Date, EndDate As Date) As Long

Dim dtLoop As Date

WeekdayDiff = 0
For dtLoop = StartDate To EndDate
If DatePart("w", dtLoop, vbMonday) < 6 Then WeekdayDiff =
WeekdayDiff + 1
Next

End Function

You might want to put some error handling code in there to make sure that
EndDate is greater than start date, or to step backwards through the dates
if endDate is less than StartDate.

HTH
Dale
 
Back
Top