Overlapping dates (1 Viewer)

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:11
Joined
Aug 30, 2003
Messages
36,137
Perhaps I'm having a brain cramp, but I'm having trouble coming up with a query to return people who are sick or on vacation at any point during a selected date range. I've attached a demo with a sample of the table in it. The important fields are OffStartDate and OffEndDate.

I need to be able to specify a "from" and "to" date, and get any record where OffStartDate and OffEndDate overlap the selected dates. For me, it gets tricky when those dates are both outside the selected dates (start date before the from, end date after the to).

TIA
 

Attachments

  • dateoverlap.zip
    21.7 KB · Views: 138

EMP

Registered User.
Local time
Today, 00:11
Joined
May 10, 2003
Messages
574
Try the query attached.
 

Attachments

  • dateoverlap.zip
    24.4 KB · Views: 183

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:11
Joined
Aug 30, 2003
Messages
36,137
Thanks EMP. I'm not at work, but a quick test looks good. I'll check it better in the morning.

Thanks again!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:11
Joined
Aug 30, 2003
Messages
36,137
I appreciate the help. I ended up with 3 different WHERE clauses, which all return the same records in my testing. Shadow's seems like the simplest approach. Hopefully I haven't missed something in the logic:

WHERE (((dbo_tblSickVac.OffStartDate)<=[Forms]![Form1]![txtToDate]) AND ((dbo_tblSickVac.OffEndDate)>=[Forms]![Form1]![txtFmDate]));

I'll be incorporating this into my application today.

Thanks again for the help!
 

dsthomson

Registered User.
Local time
Yesterday, 16:11
Joined
Aug 23, 2013
Messages
20
I have a need to find overlapping date ranges and the date overlap submitted by EMP seems to work just fine.
I have a need to find the number of days that the ranges overlap. How could I query for that?
 

dsthomson

Registered User.
Local time
Yesterday, 16:11
Joined
Aug 23, 2013
Messages
20
Re: Overlapping dates (days)

This works (adapted files from this thread).
Simple but I hope it helps someone.
 

Attachments

  • OverlappingDatesDays.accdb
    536 KB · Views: 120

Users who are viewing this thread

Top Bottom