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!