Solved

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

Posted on 2011-03-10
4
266 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

11 Experts available now in Live!

Get 1:1 Help Now