Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / December 2005

Tip: Looking for answers? Try searching our database.

Remove weekends from a date calculation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Dennis - 01 Dec 2005 18:24 GMT
I have 2 dates/times which I need to take one from the other, however if
between these 2 dates there is a weekend I need to remove 48 hrs.

How can I check if a weekend falls between 2 dates? or for that matter a
number of weekends falls between 2 dates.

Any ideas - please?
Sunil - 02 Dec 2005 06:49 GMT
hi,

use the below function ..paste it into ur module

Function find_weekdays(BegDate As Variant, EndDate As Variant) As Integer

  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
find_weekdays = Work_Days
   
End Function

and call this function from ur query with 2 parameters...

for eg:

select  find_weekdays(#12/1/2005#,#12/12/2005#)-1 will return 7...this the
number of working days..i excluded saturday and sunday....

psl let me know if this helps u

thanks

with regds

Sunil.T
Paul Dennis - 02 Dec 2005 11:54 GMT
Created the module, but having problems with the select. Trying to put it in
using the Expression Builder but getting syntax errors. Tried in a seperate
query and used the SQL and managed to save the query but now get error
'Undefined function'.

Hence I have 2 problems - why is it an undefined function and then how to
have it as another field in a larger query?

sorry to be a pain.

> hi,
>
[quoted text clipped - 37 lines]
>
> Sunil.T
Chris2 - 02 Dec 2005 13:53 GMT
> I have 2 dates/times which I need to take one from the other, however if
> between these 2 dates there is a weekend I need to remove 48 hrs.
[quoted text clipped - 3 lines]
>
> Any ideas - please?

Paul Dennis,

Calculate Number of Working Days:

http://www.mvps.org/access/datetime/date0006.htm

Sincerely,

Chris O.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.