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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datetime query not working

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

I have a SQL 7 table with a datetime field, and I'm trying to run a query that returns rows with dates less than a certain date (or between 2 dates). I've tried all kinds of formats for the date in the query: 08-14-2001 8/14/2001 2001-08-14, even adding the time on to the last one, and it isn't returning anything. Any ideas what's going on here???? What's bizarre is that, when I query for dates greater than a certain date, it returns all the rows, even when I put in a date greater than all the dates (like a 2002 date...)

Thanks,
Ray
 

You should be able to use the date column in the where clause without formatting it in any way. Just format the criteria.

Examples:

Where datecol Between '8/1/2001' and '8/14/2001'

OR

Where datecol <= 'aug 14 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.
 
Thanks Terry,

I was leaving out the quotes! Duh!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top