order varchar column by datetime

Posted on 2012-08-30
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
Question by:rgb192
    LVL 25

    Accepted Solution

       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

    LVL 22

    Assisted Solution

    ORDER BY STR_TO_DATE(CONCAT(ColumnName,'M'),'%Y-%m-%d, %h:%i%p')

    Open in new window

    LVL 22

    Expert Comment

    Sorry, I didn't refresh the page before posting

    Author Closing Comment

    thank you for date sorting

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    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…

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now