Solved

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

Posted on 2011-03-10
4
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya 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 41

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 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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