Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-12-2008, 10:55 AM
macroapa
 
Posts: n/a
DateDiff exclude weekends and holidays

Hi,

I have found the following post for calculating the diff between 2
dates excluding holidays and weekends:

http://groups.google.co.uk/group/mic...fa782204?hl=en

Now I can get it to work for just weekends, but am struggling with the
3rd argument for holidays.

I have a table called 'Holidays' which contains a list of the dates so
thought the code would be:

SELECT Avg(dhCountWorkdaysA([DateReceived],[FirstContactAttempt],
[Holidays])) AS RectToFirstContact
FROM Journey_MI;

However, it is bringing up the input box for holidays so isn't
recognising it correctly.

Does anyone have any ideas?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 08-12-2008, 11:05 AM
pietlinden@hotmail.com
 
Posts: n/a
Re: DateDiff exclude weekends and holidays

On Aug 12, 4:55*am, macroapa <macro...@hotmail.co.uk> wrote:
> Hi,
>
> I have found the following post for calculating the diff between 2
> dates excluding holidays and weekends:
>
> http://groups.google.co.uk/group/mic...s/msg/1456554b...
>
> Now I can get it to work for just weekends, but am struggling with the
> 3rd argument for holidays.
>
> I have a table called 'Holidays' which contains a list of the dates so
> thought the code would be:
>
> SELECT Avg(dhCountWorkdaysA([DateReceived],[FirstContactAttempt],
> [Holidays])) AS RectToFirstContact
> FROM Journey_MI;
>
> However, it is bringing up the input box for holidays so isn't
> recognising it correctly.
>
> Does anyone have any ideas?
>
> Thanks.


this works
http://www.datastrat.com/Code/GetBusinessDay.txt
Reply With Quote
  #3 (permalink)  
Old 08-12-2008, 11:12 AM
macroapa
 
Posts: n/a
Re: DateDiff exclude weekends and holidays


>
> this workshttp://www.datastrat.com/Code/GetBusinessDay.txt- Hide quoted text -
>
> - Show quoted text -


Thanks, but that has the format:

GetBusinessDay(datStart As Date, intDayAdd As Integer)

so thats adding business days onto the start date as opposed to
calc'ing the date different between 2 dates????
Reply With Quote
  #4 (permalink)  
Old 08-12-2008, 11:43 AM
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
 
Posts: n/a
RE: DateDiff exclude weekends and holidays

I use the following function, which uses a table Holidays with a column
HolDate of date/time data type. The reason for the name of the function BTW
is that I also have one which takes a Country as another argument and allows
for different sets of public holidays in different countries:

Public Function WorkDaysDiff_SingleCountry(varFirstDate As Variant, _
varLastDate As Variant, _
Optional blnExcludePubHols As Boolean = False)
As Variant

Dim lngDaysDiff As Long, lngWeekendDays As Long
Dim intPubHols As Integer

If IsNull(varLastDate) Or IsNull(varFirstDate) Then
Exit Function
End If


' if first date is Sat or Sun start on following Monday
Select Case WeekDay(varFirstDate, vbSunday)
Case vbSaturday
varFirstDate = varFirstDate + 2
Case vbSunday
varFirstDate = varFirstDate + 1
End Select

' if last date is Sat or Sun finish on following Monday
Select Case WeekDay(varLastDate, vbSunday)
Case vbSaturday
varLastDate = varLastDate + 2
Case vbSunday
varLastDate = varLastDate + 1
End Select

' get total date difference in days
lngDaysDiff = DateDiff("d", varFirstDate, varLastDate)

' get date difference in weeks and multiply by 2
' to get number of weekend days
lngWeekendDays = DateDiff("ww", varFirstDate, varLastDate, vbMonday) * 2

' subtract number of weekend days from total date difference
' to return number of working days
WorkDaysDiff_SingleCountry = lngDaysDiff - lngWeekendDays

' exclude public holidays if required
If blnExcludePubHols Then
intPubHols = DCount("*", "Holidays", "HolDate Between #" _
& Format(varFirstDate, "mm/dd/yyyy") & "# And #" & _
Format(varLastDate - 1, "mm/dd/yyyy") & "#")

WorkDaysDiff_SingleCountry = WorkDaysDiff_SingleCountry - intPubHols
End If

End Function

The optional blnExcludePubHols argument allows for public holidays to be
taken into account or not. By default its False, so in your query, to
exclude weekends and holidays from the count you'd call it like so:

SELECT
AVG(WorkDaysDiff_SingleCountry([DateReceived],[FirstContactAttempt],TRUE))
AS RectToFirstContact
FROM Journey_MI;

Ken Sheridan
Stafford, England

"macroapa" wrote:

> Hi,
>
> I have found the following post for calculating the diff between 2
> dates excluding holidays and weekends:
>
> http://groups.google.co.uk/group/mic...fa782204?hl=en
>
> Now I can get it to work for just weekends, but am struggling with the
> 3rd argument for holidays.
>
> I have a table called 'Holidays' which contains a list of the dates so
> thought the code would be:
>
> SELECT Avg(dhCountWorkdaysA([DateReceived],[FirstContactAttempt],
> [Holidays])) AS RectToFirstContact
> FROM Journey_MI;
>
> However, it is bringing up the input box for holidays so isn't
> recognising it correctly.
>
> Does anyone have any ideas?
>
> Thanks.
>


Reply With Quote
  #5 (permalink)  
Old 08-12-2008, 11:43 AM
Michael Gramelspacher
 
Posts: n/a
Re: DateDiff exclude weekends and holidays

On Tue, 12 Aug 2008 03:12:16 -0700 (PDT), macroapa <macroapa@hotmail.co.uk> wrote:

>
>>
>> this workshttp://www.datastrat.com/Code/GetBusinessDay.txt- Hide quoted text -
>>
>> - Show quoted text -

>
>Thanks, but that has the format:
>
>GetBusinessDay(datStart As Date, intDayAdd As Integer)
>
>so thats adding business days onto the start date as opposed to
>calc'ing the date different between 2 dates????


Although seldom mentioned, you can also use a auxillary calendar table to do these kinds of
calculations. Find one here:
http://www.psci.net/gramelsp/temp/Sa...s%202003. htm
Reply With Quote
  #6 (permalink)  
Old 08-12-2008, 11:44 AM
Douglas J. Steele
 
Posts: n/a
Re: DateDiff exclude weekends and holidays

Take a look at my September, 2004 "Access Answers" column in Pinnacle
Publication's "Smart Access". You can download the column (and sample
database) for free at http://www.accessmvp.com/DJSteele/SmartAccess.html

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"macroapa" <macroapa@hotmail.co.uk> wrote in message
news:09e14ff8-39e5-44bb-b0f3-4a4d07c99af5@w7g2000hsa.googlegroups.com...
> Hi,
>
> I have found the following post for calculating the diff between 2
> dates excluding holidays and weekends:
>
> http://groups.google.co.uk/group/mic...fa782204?hl=en
>
> Now I can get it to work for just weekends, but am struggling with the
> 3rd argument for holidays.
>
> I have a table called 'Holidays' which contains a list of the dates so
> thought the code would be:
>
> SELECT Avg(dhCountWorkdaysA([DateReceived],[FirstContactAttempt],
> [Holidays])) AS RectToFirstContact
> FROM Journey_MI;
>
> However, it is bringing up the input box for holidays so isn't
> recognising it correctly.
>
> Does anyone have any ideas?
>
> Thanks.



Reply With Quote
  #7 (permalink)  
Old 08-12-2008, 05:04 PM
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
 
Posts: n/a
Re: DateDiff exclude weekends and holidays

I'll second that. For one thing it has the advantage of portability.

Ken Sheridan
Stafford, England

"Michael Gramelspacher" wrote:

> On Tue, 12 Aug 2008 03:12:16 -0700 (PDT), macroapa <macroapa@hotmail.co.uk> wrote:
>
> >
> >>
> >> this workshttp://www.datastrat.com/Code/GetBusinessDay.txt- Hide quoted text -
> >>
> >> - Show quoted text -

> >
> >Thanks, but that has the format:
> >
> >GetBusinessDay(datStart As Date, intDayAdd As Integer)
> >
> >so thats adding business days onto the start date as opposed to
> >calc'ing the date different between 2 dates????

>
> Although seldom mentioned, you can also use a auxillary calendar table to do these kinds of
> calculations. Find one here:
> http://www.psci.net/gramelsp/temp/Sa...s%202003. htm
>


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:57 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Mortgage Calculator | Mortgage Calculator | Credit Card | Hosting | Mobile Phones



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114