Query from a date rage

M

matjcb

I have a start date and an end date on a table.

Is there a way to query a date within the start date and end date?
For example:

Table has,
Start date End date Hours per day
08-01-08 08-30-08 4
08-20-08 08-30-08 5
08-01-08 08-19-08 3

Query 08-18-08 to get “7†Hours per day
And
Query 08-22-08 to get “9†Hours per day

thx
 
J

John Spencer

The simplest method would be

WHERE #08/18/2008# Between [Start Date] and [End Date]

A bit more complex, but more efficient since it can use indexes on the fields
if they are available.

WHERE [Start Date] <= #08/18/2008# and [End Date] >= #08/18/2008#

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
D

Dirk Goldgar

in message
I have a start date and an end date on a table.

Is there a way to query a date within the start date and end date?
For example:

Table has,
Start date End date Hours per day
08-01-08 08-30-08 4
08-20-08 08-30-08 5
08-01-08 08-19-08 3

Query 08-18-08 to get “7†Hours per day
And
Query 08-22-08 to get “9†Hours per day


It's not clear exactly how you want to query this, but here's an example of
a paramter query that will do it:

SELECT
[Enter Date] AS DateQueried,
Sum(DateRanges.HoursPerDay) AS TotalHours
FROM DateRanges
WHERE [Enter Date] Between [StartDate] And [EndDate]
GROUP BY [Enter Date];
 
K

KARL DEWEY

Try this - UNTESTED --
SELECT [Enter select date] AS [Select Date], Sum([Hours per day]) AS [Total
Hours per day]
FROM YourTable
WHERE [Enter select date] Between [Start date] And [End date]
GROUP BY [Enter select date];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top