【问题标题】:Order dates in MySQL with this format "01 August 2013"MySQL 中的订单日期格式为“2013 年 8 月 1 日”
【发布时间】:2013-12-03 07:41:31
【问题描述】:

如何在 ASC 中排序日期,

日期格式如下

01 January 2013

13 August 2013

27 June 2013

我试过这个查询

SELECT * FROM table ORDER BY TIMESTAMP(date) ASC

还有这个查询

SELECT * FROM property_rent ORDER BY UNIX_TIMESTAMP(date) ASC

【问题讨论】:

  • 您想要的排序顺序是什么?
  • 从最旧到最新。似乎无法在 str_to_date 中找到正确的日期格式。
  • '%d %M %Y' 应该可以工作(假设所有行都有相同格式的数据)...但是,为什么不直接将列类型更改为 DATE?跨度>

标签: mysql sql sorting date


【解决方案1】:

使用str_to_date函数:

SELECT * FROM table ORDER BY str_to_date(date, 'your format here')

例如

SELECT * FROM table ORDER BY str_to_date(date, '%d %M %Y')

或类似的。

【讨论】:

  • 似乎有正确的答案。检查sqlfiddle代码here
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-29
  • 1970-01-01
  • 1970-01-01
  • 2013-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多