The .NET code, DateTime.Now.ToString()
outputs something like this:
11/28/2011 1:17:05 PM
I store it in MySQL as a VARCHAR
.
When I SELECT
it back to my DataTable, I would like it to be ordered. Of course since it's a VARCHAR
, a simple ORDER BY
will sort it alphabetically and not chronologically.
Is there a way to ORDER BY
this chronologically, using SQL?
You will want the STR_TO_DATE function
SELECT columns
FROM table
ORDER BY STR_TO_DATE(varCharDateColumn, '%m/%d/%Y %h:%i:%s')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.