[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Dates

Posted on 2014-12-05
11
Medium Priority
?
97 Views
Last Modified: 2014-12-15
My results are not returning the correct results.

--[ApptBookedDate] datetime
--YYYY-MM-DD HH:MI:SS

WHERE
        CONVERT(DATETIME, o.ApptBookedDateTime)  < '2014-04-12 14:00:00:000'  

returns - 2014-12-04 13:59:00.000
0
Comment
Question by:aneilg
[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
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40482512
Hi,

not really sure what is the problem here, what should be returned i.e. desired output?
0
 

Author Comment

by:aneilg
ID: 40482519
I want dates returned < 12th April 2014 - 2pm

my results return 04th December 2014.
0
 

Author Comment

by:aneilg
ID: 40482521
o.ApptBookedDateTime_dte is a datetime field.

so I should be able just to do         o.ApptBookedDateTime_dte  < '2014-04-12 14:00:00:000
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aneilg
ID: 40482522
this seems to work. o.ApptBookedDateTime_dte  < '2014-04-12'  

if I remove the HH:MI:SS but I need them in the query.
0
 
LVL 52

Accepted Solution

by:
Vitor Montalvão earned 1332 total points
ID: 40482530
You can try this:
WHERE 
         CONVERT(DATETIME, o.ApptBookedDateTime)  < CONVERT(VARCHAR,'2014-04-12 14:00:00:000',114)

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 668 total points
ID: 40482537
CONVERT(DATETIME, o.ApptBookedDateTime)

your field IS already datetime, so you shall not apply the convert function there:
see this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html
0
 

Author Comment

by:aneilg
ID: 40482544
still returns 2014-12-04 13:59:00.000

04th December
0
 
LVL 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1332 total points
ID: 40482553
Then try with code 120:
WHERE 
         CONVERT(DATETIME, o.ApptBookedDateTime)  < CONVERT(VARCHAR,'2014-04-12 14:00:00:000',120)

Open in new window

In this MSDN article you can see all available codes.
0
 

Author Comment

by:aneilg
ID: 40482556
thanks.

forgot to add

SET DATEFORMAT MDY
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40482574
>still returns 2014-12-04 13:59:00.000
so, you want to format the OUTPUT ...

which is in the SELECT itself:

SELECT CONVERT(varchar(20), o.ApptBookedDateTime, 101)
 FROM ...
WHERE  o.ApptBookedDateTime  < CONVERT(datetime, '2014-04-12 14:00:00:000'  , 120)
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40482945
<wild guess>
Copy-paste the COMPLETE WHERE clause into this question, just in case there is any logic such as AND / OR or any precedence constraints ( ) that is causing this date comparison to only fire on a subset of rows.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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