PC Review


Reply
Thread Tools Rate Thread

How do I count overlapping days in a single field of my database?

 
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      21st Feb 2006
I am trying to count overlapping dates from a single field of my program. I
have a field which has the same stock number in it. Then I have a field that
has the dates it was gone. I am trying to figure out how to count the dates
that are overlapping so I get a count of the stock number that are gone at
the same time. The stock number field and the date fields are set up in the
following format:

Stock Number Date out Date in
000000000 12Jan06 15Feb06
000000000 20Jan06 09Feb06

There are about 5000 entries in the database.

Any help would be greatly apprecitaed
 
Reply With Quote
 
 
 
 
=?Utf-8?B?bGRpYXo=?=
Guest
Posts: n/a
 
      21st Feb 2006
if you access to the code you can use '

like this

'' statement
''statement
''statement
''statement
--
Lorenzo DÃ*az
Cad Technician


"Terry" wrote:

> I am trying to count overlapping dates from a single field of my program. I
> have a field which has the same stock number in it. Then I have a field that
> has the dates it was gone. I am trying to figure out how to count the dates
> that are overlapping so I get a count of the stock number that are gone at
> the same time. The stock number field and the date fields are set up in the
> following format:
>
> Stock Number Date out Date in
> 000000000 12Jan06 15Feb06
> 000000000 20Jan06 09Feb06
>
> There are about 5000 entries in the database.
>
> Any help would be greatly apprecitaed

 
Reply With Quote
 
=?Utf-8?B?bGRpYXo=?=
Guest
Posts: n/a
 
      21st Feb 2006
Sorry I answered in the wrong post
--
Lorenzo DÃ*az
Cad Technician


"ldiaz" wrote:

> if you access to the code you can use '
>
> like this
>
> '' statement
> ''statement
> ''statement
> ''statement
> --
> Lorenzo DÃ*az
> Cad Technician
>
>
> "Terry" wrote:
>
> > I am trying to count overlapping dates from a single field of my program. I
> > have a field which has the same stock number in it. Then I have a field that
> > has the dates it was gone. I am trying to figure out how to count the dates
> > that are overlapping so I get a count of the stock number that are gone at
> > the same time. The stock number field and the date fields are set up in the
> > following format:
> >
> > Stock Number Date out Date in
> > 000000000 12Jan06 15Feb06
> > 000000000 20Jan06 09Feb06
> >
> > There are about 5000 entries in the database.
> >
> > Any help would be greatly apprecitaed

 
Reply With Quote
 
James A. Fortune
Guest
Posts: n/a
 
      21st Feb 2006
Terry wrote:
> I am trying to count overlapping dates from a single field of my program. I
> have a field which has the same stock number in it. Then I have a field that
> has the dates it was gone. I am trying to figure out how to count the dates
> that are overlapping so I get a count of the stock number that are gone at
> the same time. The stock number field and the date fields are set up in the
> following format:
>
> Stock Number Date out Date in
> 000000000 12Jan06 15Feb06
> 000000000 20Jan06 09Feb06
>
> There are about 5000 entries in the database.
>
> Any help would be greatly apprecitaed


Try my DateIntersection function in a subquery. Something like:

SELECT StockNumber, [Date out], [Date in], (SELECT COUNT(*) FROM
tblInOut AS A WHERE DateIntersection(tblInOut.[Date out], tblInOut.[Date
in], A.[Date out], A.[Date in]) > 0) AND A.[Stock Number] =
tblInOut.[Stock Number]) - 1 AS HowManyOverlapThisRange FROM tblInOut;

'Begin module code ----
Public Function DateIntersection(dt1 As Date, dt2 As Date, dt3 As Date,
dt4 As Date) As Integer
'Return the number of days overlapping two date ranges
'Assumes d1 <= d2 and d3 <= d4 Ranges can go in either order
DateIntersection = 0
If dt2 <= dt3 Then
If dt2 = dt3 Then DateIntersection = 1
Exit Function
End If
If dt4 <= dt1 Then
If dt4 = dt1 Then DateIntersection = 1
Exit Function
End If
If dt1 <= dt3 And dt3 <= dt2 And dt2 <= dt4 Then
DateIntersection = DateDiff("d", dt3, dt2) + 1
Exit Function
End If
If dt1 <= dt3 And dt3 <= dt4 And dt4 <= dt2 Then
DateIntersection = DateDiff("d", dt3, dt4) + 1
Exit Function
End If
If dt3 <= dt1 And dt1 <= dt2 And dt2 <= dt4 Then
DateIntersection = DateDiff("d", dt1, dt2) + 1
Exit Function
End If
If dt3 <= dt1 And dt1 <= dt4 And dt4 <= dt2 Then
DateIntersection = DateDiff("d", dt1, dt4) + 1
End If
End Function
'End module code ------

This will probably run slowly on 5000 records so post back if you need
something efficient so that someone else can help :-). You can also
change this function to return a boolean value instead of the number of
days that intersect. The '> 0' in the SQL would change to '= -1' if
that's done.

James A. Fortune
(E-Mail Removed)
 
Reply With Quote
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      20th Mar 2006
I Tried this Coding but it gives me all kinds of Select case and end of
statement errors!

"James A. Fortune" wrote:

> Terry wrote:
> > I am trying to count overlapping dates from a single field of my program. I
> > have a field which has the same stock number in it. Then I have a field that
> > has the dates it was gone. I am trying to figure out how to count the dates
> > that are overlapping so I get a count of the stock number that are gone at
> > the same time. The stock number field and the date fields are set up in the
> > following format:
> >
> > Stock Number Date out Date in
> > 000000000 12Jan06 15Feb06
> > 000000000 20Jan06 09Feb06
> >
> > There are about 5000 entries in the database.
> >
> > Any help would be greatly apprecitaed

>
> Try my DateIntersection function in a subquery. Something like:
>
> SELECT StockNumber, [Date out], [Date in], (SELECT COUNT(*) FROM
> tblInOut AS A WHERE DateIntersection(tblInOut.[Date out], tblInOut.[Date
> in], A.[Date out], A.[Date in]) > 0) AND A.[Stock Number] =
> tblInOut.[Stock Number]) - 1 AS HowManyOverlapThisRange FROM tblInOut;
>
> 'Begin module code ----
> Public Function DateIntersection(dt1 As Date, dt2 As Date, dt3 As Date,
> dt4 As Date) As Integer
> 'Return the number of days overlapping two date ranges
> 'Assumes d1 <= d2 and d3 <= d4 Ranges can go in either order
> DateIntersection = 0
> If dt2 <= dt3 Then
> If dt2 = dt3 Then DateIntersection = 1
> Exit Function
> End If
> If dt4 <= dt1 Then
> If dt4 = dt1 Then DateIntersection = 1
> Exit Function
> End If
> If dt1 <= dt3 And dt3 <= dt2 And dt2 <= dt4 Then
> DateIntersection = DateDiff("d", dt3, dt2) + 1
> Exit Function
> End If
> If dt1 <= dt3 And dt3 <= dt4 And dt4 <= dt2 Then
> DateIntersection = DateDiff("d", dt3, dt4) + 1
> Exit Function
> End If
> If dt3 <= dt1 And dt1 <= dt2 And dt2 <= dt4 Then
> DateIntersection = DateDiff("d", dt1, dt2) + 1
> Exit Function
> End If
> If dt3 <= dt1 And dt1 <= dt4 And dt4 <= dt2 Then
> DateIntersection = DateDiff("d", dt1, dt4) + 1
> End If
> End Function
> 'End module code ------
>
> This will probably run slowly on 5000 records so post back if you need
> something efficient so that someone else can help :-). You can also
> change this function to return a boolean value instead of the number of
> days that intersect. The '> 0' in the SQL would change to '= -1' if
> that's done.
>
> James A. Fortune
> (E-Mail Removed)
>

 
Reply With Quote
 
James A. Fortune
Guest
Posts: n/a
 
      20th Mar 2006
Terry wrote:
> I Tried this Coding but it gives me all kinds of Select case and end of
> statement errors!
>
> "James A. Fortune" wrote:
>
>
>>Terry wrote:
>>
>>>I am trying to count overlapping dates from a single field of my program. I
>>>have a field which has the same stock number in it. Then I have a field that
>>>has the dates it was gone. I am trying to figure out how to count the dates
>>>that are overlapping so I get a count of the stock number that are gone at
>>>the same time. The stock number field and the date fields are set up in the
>>>following format:
>>>
>>>Stock Number Date out Date in
>>>000000000 12Jan06 15Feb06
>>>000000000 20Jan06 09Feb06
>>>
>>>There are about 5000 entries in the database.
>>>
>>>Any help would be greatly apprecitaed

>>
>>Try my DateIntersection function in a subquery. Something like:
>>
>>SELECT StockNumber, [Date out], [Date in], (SELECT COUNT(*) FROM
>>tblInOut AS A WHERE DateIntersection(tblInOut.[Date out], tblInOut.[Date
>>in], A.[Date out], A.[Date in]) > 0) AND A.[Stock Number] =
>>tblInOut.[Stock Number]) - 1 AS HowManyOverlapThisRange FROM tblInOut;
>>
>>'Begin module code ----
>>Public Function DateIntersection(dt1 As Date, dt2 As Date, dt3 As Date,
>>dt4 As Date) As Integer
>>'Return the number of days overlapping two date ranges
>>'Assumes d1 <= d2 and d3 <= d4 Ranges can go in either order
>>DateIntersection = 0
>>If dt2 <= dt3 Then
>> If dt2 = dt3 Then DateIntersection = 1
>> Exit Function
>>End If
>>If dt4 <= dt1 Then
>> If dt4 = dt1 Then DateIntersection = 1
>> Exit Function
>>End If
>>If dt1 <= dt3 And dt3 <= dt2 And dt2 <= dt4 Then
>> DateIntersection = DateDiff("d", dt3, dt2) + 1
>> Exit Function
>>End If
>>If dt1 <= dt3 And dt3 <= dt4 And dt4 <= dt2 Then
>> DateIntersection = DateDiff("d", dt3, dt4) + 1
>> Exit Function
>>End If
>>If dt3 <= dt1 And dt1 <= dt2 And dt2 <= dt4 Then
>> DateIntersection = DateDiff("d", dt1, dt2) + 1
>> Exit Function
>>End If
>>If dt3 <= dt1 And dt1 <= dt4 And dt4 <= dt2 Then
>> DateIntersection = DateDiff("d", dt1, dt4) + 1
>>End If
>>End Function
>>'End module code ------
>>
>>This will probably run slowly on 5000 records so post back if you need
>>something efficient so that someone else can help :-). You can also
>>change this function to return a boolean value instead of the number of
>>days that intersect. The '> 0' in the SQL would change to '= -1' if
>>that's done.
>>
>>James A. Fortune
>>(E-Mail Removed)
>>


Terry,

The part before 'Begin module code ---- is meant to be the SQL for a
query rather than code inside a module or behind a form. When you're in
the Query Designer look for the SQL button.

James A. Fortune
(E-Mail Removed)
 
Reply With Quote
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      20th Mar 2006
I still get Extra ) in query expression

"James A. Fortune" wrote:

> Terry wrote:
> > I Tried this Coding but it gives me all kinds of Select case and end of
> > statement errors!
> >
> > "James A. Fortune" wrote:
> >
> >
> >>Terry wrote:
> >>
> >>>I am trying to count overlapping dates from a single field of my program. I
> >>>have a field which has the same stock number in it. Then I have a field that
> >>>has the dates it was gone. I am trying to figure out how to count the dates
> >>>that are overlapping so I get a count of the stock number that are gone at
> >>>the same time. The stock number field and the date fields are set up in the
> >>>following format:
> >>>
> >>>Stock Number Date out Date in
> >>>000000000 12Jan06 15Feb06
> >>>000000000 20Jan06 09Feb06
> >>>
> >>>There are about 5000 entries in the database.
> >>>
> >>>Any help would be greatly apprecitaed
> >>
> >>Try my DateIntersection function in a subquery. Something like:
> >>
> >>SELECT StockNumber, [Date out], [Date in], (SELECT COUNT(*) FROM
> >>tblInOut AS A WHERE DateIntersection(tblInOut.[Date out], tblInOut.[Date
> >>in], A.[Date out], A.[Date in]) > 0) AND A.[Stock Number] =
> >>tblInOut.[Stock Number]) - 1 AS HowManyOverlapThisRange FROM tblInOut;
> >>
> >>'Begin module code ----
> >>Public Function DateIntersection(dt1 As Date, dt2 As Date, dt3 As Date,
> >>dt4 As Date) As Integer
> >>'Return the number of days overlapping two date ranges
> >>'Assumes d1 <= d2 and d3 <= d4 Ranges can go in either order
> >>DateIntersection = 0
> >>If dt2 <= dt3 Then
> >> If dt2 = dt3 Then DateIntersection = 1
> >> Exit Function
> >>End If
> >>If dt4 <= dt1 Then
> >> If dt4 = dt1 Then DateIntersection = 1
> >> Exit Function
> >>End If
> >>If dt1 <= dt3 And dt3 <= dt2 And dt2 <= dt4 Then
> >> DateIntersection = DateDiff("d", dt3, dt2) + 1
> >> Exit Function
> >>End If
> >>If dt1 <= dt3 And dt3 <= dt4 And dt4 <= dt2 Then
> >> DateIntersection = DateDiff("d", dt3, dt4) + 1
> >> Exit Function
> >>End If
> >>If dt3 <= dt1 And dt1 <= dt2 And dt2 <= dt4 Then
> >> DateIntersection = DateDiff("d", dt1, dt2) + 1
> >> Exit Function
> >>End If
> >>If dt3 <= dt1 And dt1 <= dt4 And dt4 <= dt2 Then
> >> DateIntersection = DateDiff("d", dt1, dt4) + 1
> >>End If
> >>End Function
> >>'End module code ------
> >>
> >>This will probably run slowly on 5000 records so post back if you need
> >>something efficient so that someone else can help :-). You can also
> >>change this function to return a boolean value instead of the number of
> >>days that intersect. The '> 0' in the SQL would change to '= -1' if
> >>that's done.
> >>
> >>James A. Fortune
> >>(E-Mail Removed)
> >>

>
> Terry,
>
> The part before 'Begin module code ---- is meant to be the SQL for a
> query rather than code inside a module or behind a form. When you're in
> the Query Designer look for the SQL button.
>
> James A. Fortune
> (E-Mail Removed)
>

 
Reply With Quote
 
James A. Fortune
Guest
Posts: n/a
 
      21st Mar 2006
Terry wrote:
> I still get Extra ) in query expression
>
> "James A. Fortune" wrote:
>
>
>>Terry wrote:
>>
>>>I Tried this Coding but it gives me all kinds of Select case and end of
>>>statement errors!
>>>
>>>"James A. Fortune" wrote:
>>>
>>>
>>>
>>>>Terry wrote:
>>>>
>>>>
>>>>>I am trying to count overlapping dates from a single field of my program. I
>>>>>have a field which has the same stock number in it. Then I have a field that
>>>>>has the dates it was gone. I am trying to figure out how to count the dates
>>>>>that are overlapping so I get a count of the stock number that are gone at
>>>>>the same time. The stock number field and the date fields are set up in the
>>>>>following format:
>>>>>
>>>>>Stock Number Date out Date in
>>>>>000000000 12Jan06 15Feb06
>>>>>000000000 20Jan06 09Feb06
>>>>>
>>>>>There are about 5000 entries in the database.
>>>>>
>>>>>Any help would be greatly apprecitaed
>>>>
>>>>Try my DateIntersection function in a subquery. Something like:
>>>>
>>>>SELECT StockNumber, [Date out], [Date in], (SELECT COUNT(*) FROM
>>>>tblInOut AS A WHERE DateIntersection(tblInOut.[Date out], tblInOut.[Date
>>>>in], A.[Date out], A.[Date in]) > 0) AND A.[Stock Number] =
>>>>tblInOut.[Stock Number]) - 1 AS HowManyOverlapThisRange FROM tblInOut;
>>>>
>>>>'Begin module code ----
>>>>Public Function DateIntersection(dt1 As Date, dt2 As Date, dt3 As Date,
>>>>dt4 As Date) As Integer
>>>>'Return the number of days overlapping two date ranges
>>>>'Assumes d1 <= d2 and d3 <= d4 Ranges can go in either order
>>>>DateIntersection = 0
>>>>If dt2 <= dt3 Then
>>>> If dt2 = dt3 Then DateIntersection = 1
>>>> Exit Function
>>>>End If
>>>>If dt4 <= dt1 Then
>>>> If dt4 = dt1 Then DateIntersection = 1
>>>> Exit Function
>>>>End If
>>>>If dt1 <= dt3 And dt3 <= dt2 And dt2 <= dt4 Then
>>>> DateIntersection = DateDiff("d", dt3, dt2) + 1
>>>> Exit Function
>>>>End If
>>>>If dt1 <= dt3 And dt3 <= dt4 And dt4 <= dt2 Then
>>>> DateIntersection = DateDiff("d", dt3, dt4) + 1
>>>> Exit Function
>>>>End If
>>>>If dt3 <= dt1 And dt1 <= dt2 And dt2 <= dt4 Then
>>>> DateIntersection = DateDiff("d", dt1, dt2) + 1
>>>> Exit Function
>>>>End If
>>>>If dt3 <= dt1 And dt1 <= dt4 And dt4 <= dt2 Then
>>>> DateIntersection = DateDiff("d", dt1, dt4) + 1
>>>>End If
>>>>End Function
>>>>'End module code ------
>>>>
>>>>This will probably run slowly on 5000 records so post back if you need
>>>>something efficient so that someone else can help :-). You can also
>>>>change this function to return a boolean value instead of the number of
>>>>days that intersect. The '> 0' in the SQL would change to '= -1' if
>>>>that's done.
>>>>
>>>>James A. Fortune
>>>>(E-Mail Removed)
>>>>

>>
>>Terry,
>>
>>The part before 'Begin module code ---- is meant to be the SQL for a
>>query rather than code inside a module or behind a form. When you're in
>>the Query Designer look for the SQL button.
>>
>>James A. Fortune
>>(E-Mail Removed)
>>


Ah... I see the problem now. It is "Something like:" :-).

I didn't paste the SQL from a working query. It was off the top of my
head. That's why the parentheses didn't match up. What was I thinking?
Try changing "WHERE DateIntersection..." to "WHERE (DateIntersection..."

I can't guarantee that will work either, but it's my best guess since I
don't know if " > 0 AND..." will try some weird binary operation that
will always come out False without looking up operator precedence in the
Help File.

James A. Fortune
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
database field - merge single field from excel list Big Bad Bev Microsoft Word Document Management 1 7th Jun 2008 10:34 PM
Adding a single field from a access database to frontpage2003 =?Utf-8?B?U3R1Sm9s?= Microsoft Frontpage 1 30th Apr 2007 01:41 AM
Count Employee Work Time - Don't Double-count Overlapping Apts. =?Utf-8?B?Sg==?= Microsoft Excel Worksheet Functions 0 27th Apr 2007 05:52 AM
Dividing a time span into shifts - overlapping days =?Utf-8?B?SGVpZGk=?= Microsoft Excel Worksheet Functions 17 28th Feb 2006 01:40 AM
Count # of days from a specific date that's not a field? =?Utf-8?B?I0AkJWhlbHAh?= Microsoft Access Getting Started 3 5th Nov 2005 12:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:43 AM.