Solved

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

Posted on 2011-03-10
4
316 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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