Sort table with time field excluding time of day

I have a table in Mysql (firstname, lastname, data1, data2, ...) that one field name is MYDATE , and the type of this field is timestamp . In this field, the date is saved as (yyyy-mm-dd mm: ss: ms), and there are many entries in this table.

I want to write a select query sorting this table using (yyyy-mm-dd) and ignoring (mm: ss: ms).

+6
source share
3 answers
 ORDER BY date(mydate) 

but it will cause fullscan.

+7
source

Just add it to the date in your order on offer:

 SELECT columns FROM some_table ORDER BY CAST(mydate AS date); 
+3
source
 select columns from table_name order by date_format(date_column, '%Y-%m-%d') 
+2
source

Source: https://habr.com/ru/post/887542/


All Articles