A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Date diff excluding weekends



 
 
Thread Tools Display Modes
  #1  
Old December 19th, 2007, 12:57 AM posted to microsoft.public.access.queries
DeanT
external usenet poster
 
Posts: 10
Default 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  
Old December 19th, 2007, 02:51 AM posted to microsoft.public.access.queries
raskew via AccessMonster.com
external usenet poster
 
Posts: 370
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.