Connecting Tech Pros Worldwide Forums | Help | Site Map

Help between to dates

clwoods
Guest
 
Posts: n/a
#1: Nov 12 '05
Can anyone please help me.

I need to count the number of days in the month between 2 dates ie

25/01/03 to 25/06/03 I need to now how many weekdays there was say from
January 25 to the end of that month and then and the how many weekdays was
in the next month and so on for each month until the end period, I hope your
still wiith me so far. some times the end date maybe blank therefor the end
date would need to be stated somehow. I know I have ask a lot already but if
possible the number of days would also need to exclude any bank holidays etc
as identified.

If anyone has the answer to my problem I would be very greatful.

Many Thanks

Colin





Rich P
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Help between to dates


One way to approach this would be the Non-Fancy (free of charge/off the
top of my head) way. First you have to get the number of months between
the 2 dates

Sub GetDayCounts()
Dim....
sDate = StartDate
m = DateDiff("m", EndDate, StartDate)
For i = 1 to m - 1
str1 = Month(sDate) & "/1/" & Year(sDate)
eDate = str1
eDate = DateAdd("m", 1, eDate) - 1
n = DateDiff("d", eDate, sDate)
for j = 0 to n - 1
nDate = DateAdd("d", j, sDate)
If WeekDay(nDate) <> 0 And WeekDay(nDate) <> 7 Then
If Not fcnHolidays(nDate) Then
DayCount = DayCount + 1
End If
End If
Next
Debug.Print "Number of non-holiday weekdays between " _
& sDate & " and " & edate & " is " & DayCount
DayCount = 0
sDate = eDate + 1 'start next month
Next
n = DateDiff("d", EndDate, sDate) 'get last month count
for j = 0 to n - 1
nDate = DateAdd("d", j, sDate)
If WeekDay(nDate) <> 0 And WeekDay(nDate) <> 7 Then
If Not fcnHolidays(nDate) Then
DayCount = DayCount + 1
End If
End If
Next
Debug.Print "Number of non-holiday weekdays between " _
& sDate & " and " & EndDate & " is " & DayCount
End Sub

Function fcnHolidays(n As Date) As Boolean
fcnHolidays = False
Select Case n
Case #2/14/03# : fcnHolidays = True
Case #7/4/03# : fcnHolidays = True
Case #9/2/03# : fcnHoldidays = True
...
End Select
End Function

I obviously made up the holidays in the holiday function, but hopefully
you get the idea of one way to do this.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
clwoods
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Help between to dates


Rich

Many Many thanks

Colin

Rich P <rpng123@aol.com> wrote in message
news:3fce7dc5$0$88388$75868355@news.frii.net...[color=blue]
> One way to approach this would be the Non-Fancy (free of charge/off the
> top of my head) way. First you have to get the number of months between
> the 2 dates
>
> Sub GetDayCounts()
> Dim....
> sDate = StartDate
> m = DateDiff("m", EndDate, StartDate)
> For i = 1 to m - 1
> str1 = Month(sDate) & "/1/" & Year(sDate)
> eDate = str1
> eDate = DateAdd("m", 1, eDate) - 1
> n = DateDiff("d", eDate, sDate)
> for j = 0 to n - 1
> nDate = DateAdd("d", j, sDate)
> If WeekDay(nDate) <> 0 And WeekDay(nDate) <> 7 Then
> If Not fcnHolidays(nDate) Then
> DayCount = DayCount + 1
> End If
> End If
> Next
> Debug.Print "Number of non-holiday weekdays between " _
> & sDate & " and " & edate & " is " & DayCount
> DayCount = 0
> sDate = eDate + 1 'start next month
> Next
> n = DateDiff("d", EndDate, sDate) 'get last month count
> for j = 0 to n - 1
> nDate = DateAdd("d", j, sDate)
> If WeekDay(nDate) <> 0 And WeekDay(nDate) <> 7 Then
> If Not fcnHolidays(nDate) Then
> DayCount = DayCount + 1
> End If
> End If
> Next
> Debug.Print "Number of non-holiday weekdays between " _
> & sDate & " and " & EndDate & " is " & DayCount
> End Sub
>
> Function fcnHolidays(n As Date) As Boolean
> fcnHolidays = False
> Select Case n
> Case #2/14/03# : fcnHolidays = True
> Case #7/4/03# : fcnHolidays = True
> Case #9/2/03# : fcnHoldidays = True
> ...
> End Select
> End Function
>
> I obviously made up the holidays in the holiday function, but hopefully
> you get the idea of one way to do this.
>
> Rich
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


Rich P
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Help between to dates


No problem. I had to hang loose for a few minutes while another
procedure was running on another machine. This helped reduce the stress
incase my other procedure bombed out (it didn't bomb out :).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread


Similar Microsoft Access / VBA bytes