Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help searching for a date

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2007-10-12 : 11:10:02

field is define as appt_date (datetime,null)

information in field is formatted as the following
2007-11-15 00:00:00.000
2007-05-15 00:00:00.000


How do I search for the date 05/15/2007

I am doing the following
select * from testtable where appt_date between '05/15/2007' and '05/15/2007'

Is that ok or is there a better way.

Help

Howard

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-12 : 11:11:02
select * from testtable where appt_date = '05/15/2007'

select * from testtable where appt_date >= '05/15/2007' and appt_date < '05/16/2007'





E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-12 : 11:20:50
between '05/15/2007' and '05/15/2007'

is UP TO Midnight 14/15th May. So if appt_date has some Time, in addition to the Date, you need to do

< '05/16/2007'

as the upper-bound, as Peso said, so that you include any appt_date pm 15th, containing time, up to (but not including) midnight 15/16th [which is considered to be the 16th, and not the 15th!]

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-15 : 03:24:21
Also dont forget to express dates in YYYYMMDD format

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-15 : 03:56:17
Oops!
Go to Top of Page
   

- Advertisement -