Connecting Tech Pros Worldwide Forums | Help | Site Map

Date Queries

Colin Mardell
Guest
 
Posts: n/a
#1: Nov 13 '05
I have a table with two fields, 'StartDate' and 'EndDate'. How do I
get the query to select a record that matches a given date that is
between the two dates?

Bas Cost Budde
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Date Queries


Colin Mardell wrote:[color=blue]
> I have a table with two fields, 'StartDate' and 'EndDate'. How do I
> get the query to select a record that matches a given date that is
> between the two dates?[/color]

I'd bet upon

SELECT * FROM yourtable WHERE [enter date:] BETWEEN startdate AND enddate

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
CodeDevil
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Date Queries


hmmm...

well... if you're thinking of retrieving one single record with your
query, well, unless you are sure you have one and only one record that
has this date value that falls between the startDate and endDate then
you'll be recieving more than one.

Also, knowing which database would help, but here is how I'd do it in
SQl Server 2000

select [someField] from [someTable] where ([dateField] > @startDate and
[dateField] < @endDate)


In Oracle we take advantage of the between keyword
select [someField] from [someTable] where ([dateField] BETWEEN
@startDate and @endDate)

*keep in mind that in Oracle, between includes the startDate and endDate


**@paramName is a parameter name that you pass on to the query.

cheers

got a code problem? hand it to the devil.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Keith
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Date Queries


Colin,

On the query grid, in the criteria for *both* fields, try this:

[EnterDate] Between [StartDate] And [EndDate]

When you run the query it will prompt you to enter a date and should
return records where the entered date is between the two.

HTH - Keith.
www.keithwilby.com

Colin Mardell wrote:
[color=blue]
> I have a table with two fields, 'StartDate' and 'EndDate'. How do I
> get the query to select a record that matches a given date that is
> between the two dates?[/color]
Ross Presser
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Date Queries


CodeDevil <CodeDevil@thedevils.com> wrote in
news:1102245849.ojdwXr8WrLrY+qlhjW8iUA@teranews:
[color=blue]
> In Oracle we take advantage of the between keyword
> select [someField] from [someTable] where ([dateField] BETWEEN
> @startDate and @endDate)
>
> *keep in mind that in Oracle, between includes the startDate and endDate[/color]

The BETWEEN keyword does exist in both SQL Server and in Access, and
behaves the exact same way.
Closed Thread