473,499 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to obtain part of a date range

The short version;
In short, given one date range (start and end dates) how can I find the
period that overlaps with another date range?

The long version;
I have knocked up a little application that helps my friend monitor employee
absences.

You can enter the start and end dates of an absence. For reports the user
specifies start and end dates which produces a list of people with absences
in that period. Only problem is if someone's absence overlaps into the
report period.

e.g report covers March 1st to April 1st but won't include an absence that
started on Jan 1st and finished on March 20th. In that case I need to pick
up that overlapping absence which would be March 1st to March 20th.

Looking at it now I can't understand how I missed something so obvious but I
can't work out how to revise my queries.

Any suggestions?
Apr 4 '08 #1
3 2309
What you want is [StartDate]<= [EndRange] AND [EndDate] >=[StartRange].
That will pick up your 1/1 - 3/20 absence, but what about absences that are
unfinished? If the report covered Feb 1 - Mar 1 your 1/1 - 3/20 wouldn't
meet the criteria, so you need to add a second criterion: [StartDate] <=
[EndRange] AND [EndDate] Is Null.

"Deano" <de***@mailinator.comwrote in message
news:65*************@mid.individual.net...
The short version;
In short, given one date range (start and end dates) how can I find the
period that overlaps with another date range?

The long version;
I have knocked up a little application that helps my friend monitor
employee
absences.

You can enter the start and end dates of an absence. For reports the user
specifies start and end dates which produces a list of people with
absences
in that period. Only problem is if someone's absence overlaps into the
report period.

e.g report covers March 1st to April 1st but won't include an absence that
started on Jan 1st and finished on March 20th. In that case I need to
pick
up that overlapping absence which would be March 1st to March 20th.

Looking at it now I can't understand how I missed something so obvious but
I
can't work out how to revise my queries.

Any suggestions?


Apr 4 '08 #2
On Apr 3, 8:14*pm, "Deano" <de...@mailinator.comwrote:
The short version;
In short, given one date range (start and end dates) how can I find the
period that overlaps with another date range?

The long version;
I have knocked up a little application that helps my friend monitor employee
absences.

You can enter the start and end dates of an absence. *For reports the user
specifies start and end dates which produces a list of people with absences
in that period. *Only problem is if someone's absence overlaps into the
report period.

e.g report covers March 1st to April 1st but won't include an absence that
started on Jan 1st and finished on March 20th. *In that case I need to pick
up that overlapping absence which would be March 1st to March 20th.

Looking at it now I can't understand how I missed something so obvious butI
can't work out how to revise my queries.

Any suggestions?
In:

http://groups.google.com/group/comp....fe893be4b75102

I gave a function called DateIntersection that calculates the number
of days of overlap between two date ranges. In that post I also said:

"For the solution shown above, the DateIntersection function can be
replaced by an appropriate SQL expression for greater range of
applicability."

What I meant by that was that the function was intended to be used as
a tool to get something working right away. The function allows the
range logic to be encapsulated while the basic problem logic is
pondered as a way of controlling the complexity. Once the basic
problem logic is working I usually replace the function by a SQL
statement so that the answer is dependent only on SQL rather than on
SQL in conjunction with a User Defined Function (UDF).

Two date ranges overlap if DateIntersection(dt1, dt2, dt3, dt4) 0.

James A. Fortune
CD********@FortuneJames.com
Apr 4 '08 #3
To prevent collisions, the logic here is quite simple:
A collision occurs when:
RequestStartDate <= EndDate
and
RequestEndDate >= StartDate
The above is thus a rather simply query, but if any collision occurs, the
above will return records..and you simply don't allow the booking. In other
words, since we NEVER allow booking with a collision, then the above simply
statement will work for us.
dim strWhere as string
dim dtRequeestStartDate as date
dim dtRequestEndDate as date
dtRequestStartDate = inputbox("Enter start Date")
dtRequestEndDate = inputbox("Enter end date")
strWhere="#" & format(dtRequestStartDate,"mm/*dd/yyyy") & "# <= EndDate" & _
" and #" & format(dtRequestEndDate,"mm/dd*/yyyy") & "# >= StartDate"
if dcount("*","tableBooking",strW*here) 0 then
msgbox "sorry, you can't book
....bla bla bla....
The above is just an example, and I am sure you would build a nice form that
prompts the user for the booking dates. However, what is nice here is that
the simple conditions above does return ANY collisions....
--

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
Apr 4 '08 #4

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

Similar topics

0
3067
by: ImraneA | last post by:
Hi there Many thanks to those people who contributed to this group, helped me greatly. Enclose, my code, hope it helps others :- Public Function Export_Excel_9(tbx1 As Variant, tbx2 As...
3
7445
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
6
3222
by: alexanderpope11 | last post by:
Hello, how do I write this SQL: I would like to check the Main table for invalid rows. An invalid row is: any row where the Start_date to stop_date range overlaps an invalid date in the Code...
5
1484
by: kavithadevan | last post by:
Hi, Here is the script which i am working in this script i am trying to search some events for that i developed this .Its working but if there is no events means i want to display there is no...
19
3904
by: ali3n8 | last post by:
Hello I have attempted to create a date range report from a query called qrycustomerinformation. The field that contains the value of my date is called Followup. When i run a report on this it is...
4
2835
Sandboxer
by: Sandboxer | last post by:
I want to be able to program Access to provide for me, by individual day, what my contract obligations are to my customers. Will Access recognize all the individual days in between a date range...
2
1688
by: grego9 | last post by:
I have a problem in Excel 2000. I have written some VBA code that transfers data from the current excel workbook to a file called "Deal Input2.xls". Everything transfers ok apart from the date in...
13
3964
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
19
5982
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
0
7128
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
7215
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
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5467
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,...
1
4917
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...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.