473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Help between to dates

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
Nov 12 '05 #1
3 1721
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!
Nov 12 '05 #2
Rich

Many Many thanks

Colin

Rich P <rp*****@aol.com> wrote in message
news:3f***********************@news.frii.net...
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!

Nov 12 '05 #3
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!
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
2
by: Ian DeRock | last post by:
I'm fairly new to XML. As I can see it, XML is a way to organize data like in a table in a RDB, or the RDB itself. I have used XML in application data, but did not design the actual XML. I...
8
by: Shlomi Schwartz | last post by:
Hi all, Why do I get the folowing date when creating it like so: var d = new Date(2003,9,2); Wed Oct 1 23:00:00 UTC+0200 2003 Isent it soposed to be:
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
5
by: Alicia | last post by:
Yes, but will that skip a week and group by the date for me? I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date ...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
2
by: mario | last post by:
Hi, I have verry big problem. I must write function using dates. This is a problem: I have some dates for example: 2006-01-01, 2006-02-05, 2006-10-15 etc. then some times: 20sec, 50sec, 45sec...
4
by: Steve Chow | last post by:
I was wondering if someone could help with my assignment. I've pretty done finished the work but cannot figure out why it only prints the last one added. Here is my code. The way things are done...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.