Solved

SQL select statement where date = '1/2/2008'

Posted on 2011-03-10
4
279 Views
Last Modified: 2012-05-11
For the life of me I can't figure this one out. I am trying to query a database and return records for a single day, btu keep getting erroneus results and now I see why. How can I make this work?

select *
from [userTable]
where myDate>= '1/2/2008'
AND myDate<='1/2/2008'

myDate looks like this 2008-01-02 10:55:40.0000000

There has got to be an easier way. lol.

thanks.

Jim
0
Comment
Question by:JimmyDeuce
4 Comments
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 50 total points
ID: 35101364

declare @MyDate DateTime
set @MyDate = '1/2/2008'

select *
from [userTable]
where myDate >= @MyDate
AND myDate < DATEADD(DD, 1, @MyDate)
0
 
LVL 40

Accepted Solution

by:
Sharath earned 375 total points
ID: 35101436
you have to provide the time part as well.
select * 
from [userTable] 
where myDate>= '1/2/2008'
AND mydate <='1/2/2008 23:59:59'

Open in new window

0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 25 total points
ID: 35105855
how to hande date/time correctly: read this article
http://www.experts-exchange.com/A_1499.html
0
 
LVL 5

Assisted Solution

by:NARANTHIRAN
NARANTHIRAN earned 50 total points
ID: 35106181
Try using the following query in the following format.
select *
from [userTable]
where myDate>= '2008-02-01'
AND myDate<='2008-02-01'

i think this may help u..
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now