If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Date diff excluding weekends
Is there a formula I can use in a query to calc the diff between 2 dates
excluding weekends (Sat and Sun) ? Thanks |
#2
|
|||
|
|||
Date diff excluding weekends
Dean -
Try this: Function DateDiffW(BegDate As Date, EndDate As Date) As Integer 'Returns number of days, excluding Saturday and Sunday 'As written, counts both BegDate and EndDate, e.g., 'Monday - Friday would count as 5 days 'coded by: raskew Const SUNDAY = 1 Const SATURDAY = 7 Dim NumWeeks As Integer If BegDate EndDate Then DateDiffW = 0 Else Select Case WeekDay(BegDate) Case SUNDAY: BegDate = BegDate + 1 Case SATURDAY: BegDate = BegDate + 2 End Select Select Case WeekDay(EndDate) Case SUNDAY: EndDate = EndDate - 2 Case SATURDAY: EndDate = EndDate - 1 End Select NumWeeks = DateDiff("ww", BegDate, EndDate) DateDiffW = NumWeeks * 5 + WeekDay(EndDate) - WeekDay(BegDate) + 1 End If End Function HTH - Bob DeanT wrote: Is there a formula I can use in a query to calc the diff between 2 dates excluding weekends (Sat and Sun) ? Thanks -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...eries/200712/1 |
Thread Tools | |
Display Modes | |
|
|