Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare date

Status
Not open for further replies.

specv

Programmer
Aug 8, 2001
42
CA
Hi

I want to select the records where the date is between 2 others dates.

How can I do this?

Thanks

Phil
 

Select * From table
Where datecol Between '07/01/2001/ And '07/31/2001'

Or

Select * From table
Where datecol >= '07/01/2001/ And datecol <= '07/31/2001'
Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
SELECT whatever
FROM your_table
WHERE the_date_column BETWEEN earliest_date AND latest_date;
 
Looks like Terry and I saw your post at about the same time.

Two points bear mentioning here:

1. Terry's query includes quotes around the date strings, which WILL be necessary if you are using literals instead of variables for the comparison.

2. Be sure to use the date format your database expects. In Oracle, the default format is '08-AUG-01', but it may be different for your particular RDBMS or setup.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top