Reputation: 1409
I have a table in Mysql (firstname,lastname,data1,data2,...) that one field name is MYDATE and type of this field is timestamp
. In this field, the date saved as (yyyy-mm-dd mm:ss:ms), and there are many records of this table.
I want write a select query that sort this table with (yyyy-mm-dd) and without considering (mm:ss:ms).
Upvotes: 7
Views: 4973
Reputation: 2753
select columns
from table_name
order by date_format(date_column, '%Y-%m-%d')
Upvotes: 3
Reputation: 434835
Just cast it to a date in your order by clause:
SELECT columns
FROM some_table
ORDER BY CAST(mydate AS date);
Upvotes: 3