Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

order varchar column by datetime

Posted on 2012-08-30
4
Medium Priority
?
1,280 Views
Last Modified: 2012-08-30
varchar column
2012-08-30,  7:09P
2012-08-30, 10:26A

want to order by datetime


I am told do not change the table structure
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 1000 total points
ID: 38352803
use
   str_to_date(concat(date_char,'M'),'%Y-%m-%d, %l:%i%p')
to turn it into a datetime, e.g.
select date_char
     , str_to_date(concat(date_char,'M'),'%Y-%m-%d, %l:%i%p')
from (select '2012-08-30,  7:09P' as date_char union all
      select '2012-08-30, 10:26A' as date_char)v
order by str_to_date(concat(date_char,'M'),'%Y-%m-%d, %l:%i%p')

Open in new window

0
 
LVL 22

Assisted Solution

by:Thomasian
Thomasian earned 1000 total points
ID: 38352814
ORDER BY STR_TO_DATE(CONCAT(ColumnName,'M'),'%Y-%m-%d, %h:%i%p')

Open in new window

0
 
LVL 22

Expert Comment

by:Thomasian
ID: 38352819
Sorry, I didn't refresh the page before posting
0
 

Author Closing Comment

by:rgb192
ID: 38352838
thank you for date sorting
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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…
Suggested Courses

810 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