[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to sort on datetime datatype

Posted on 2008-06-18
3
Medium Priority
?
1,180 Views
Last Modified: 2008-06-18
How can I sort on a datetime datatype

11/01/2002 09:35:19
11/01/2002 11:35:10
11/01/2002 07:35:09

order by does not give the correct results.   I need to be able to sort on date then the time part of the date
0
Comment
Question by:mugsey
[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
  • 2
3 Comments
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 21811369
Try this:

ORDER BY CAST(YouDateTimeField AS sql_variant)

Open in new window

0
 
LVL 33

Expert Comment

by:jppinto
ID: 21811370
If you have the data as Date/Time format it will sort correctly. If you have your data as text it will not sort correctly.

jppinto
0
 
LVL 12

Accepted Solution

by:
Mortaza Doulaty earned 2000 total points
ID: 21811387
But simply using ORDER BY should work...

It displays:

2002-11-01 07:35:09.000
2002-11-01 09:35:19.000
2002-11-01 11:35:10.000

Isn't this what you expect?
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 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