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 2000 Forums
 SQL Server Development (2000)
 datetime datatype problem

Author  Topic 

ppuar
Starting Member

28 Posts

Posted - 2002-05-17 : 12:48:44
Greetings,

I am having a problem with datetime datatype

I would like to pull records from the database that have the following date '2002-05-07' and time does not matter.

When I use the following query, I get 0 results

select * from sometable where insertdate = '2002-05-07'

But, if I use the following query, I get some results

select * from sometable where insertdate >= '2002-05-07'

I know it is the time that is screwing me up. Does anyone know if there a way to run the query without time?

Thanks
P


Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-17 : 13:00:44
there are any number of ways to do this ....

where insertdate between '2002-05-07 0:00.00' and '2002-05-07 11:59.59'

... alternatively you can play with datediff, datepart, day, month, year ... choice your poison

<O>
Go to Top of Page

dsdeming

479 Posts

Posted - 2002-05-17 : 22:52:53
If time is unimportant, you can also use CONVERT:

CONVERT( char( 8 ), columnname, 112 ) = CONVERT( char( 8 ), @variable, 112 )

or something like that.

HTH

Go to Top of Page
   

- Advertisement -