简体   繁体   English

MySQL确实按日期排序

[英]MySQL doesent sort by date

I'm trying to run this query: 我正在尝试运行此查询:

$query = "SELECT * FROM `official_holiday` ORDER BY `official_holiday`.`date` desc";

I even generated the query with PHPMyAdmin just to be sure its correct. 我什至用PHPMyAdmin生成了查询,以确保其正确。 I dont why it does not order at all and just takes the dates as they are in the DB. 我不知道为什么它根本不排序,而只是按照数据库中的日期进行排序。

How can I order by date? 如何按日期订购? I just want to echo the results with the smallest date first from the fetched result array. 我只想从获取的结果数组中首先以最小的日期回显结果。

Thanks in advance 提前致谢

E// E // 在此处输入图片说明

Change your query like this 像这样更改您的查询

SELECT * FROM `official_holiday` ORDER BY DATE(`official_holiday`.`date`) desc.

It will work fine. 它将正常工作。

SELECT * FROM `official_holiday` ORDER BY date DESC.

This should work, as long as your dates are stored in the correct format. 只要您的日期以正确的格式存储,此方法就可以工作。

Nice and simple. 漂亮又简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM