How does mysql sort by string date?

Source: Internet
Author: User
How does mysql sort by string date? The date in the table uses varchar type date data, value (for example, 20130301,20130201, 20130101 ...)
The expected function is to select the latest month value of the date based on the year and month. can it be implemented in an SQL statement? (Php + mysql)

Please give me some advice and wait online!


Reply to discussion (solution)

Select timestampdiff (MONTH, '20140901', now ())

Thanks to the moderator xuzuning! But I tested it. it seems wrong? Is the data in my table, and the result returned by your statement.
Year is also required for sorting. Please help me. thank you.

I just want to give an example of how to use it and how to card your scenario
SELECT $ from tbl_name order by TIMESTAMPDIFF (YEAR, fpdm, now (), TIMESTAMPDIFF (MONTH, fpdm, now ())

Without tbl_name, I don't know anything.

Haha, I am a Tom. thank you very much. well, what else do I know? thanks to the moderator!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.