从数据库检索日期 [英] Retrieve date's from database

查看:121
本文介绍了从数据库检索日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个release_date行
现在我想要显示最新的日期

i got a release_date row in my database now i want too display the latest date on top

我的查询现在: $ sql =SELECT * FROM games ORDER BY release_date ASC;

但这个ORDER BY只是获得第一个数字(天)日期
现在我得到:

but this ORDER BY just get the first digits (day) of the date Now i get:

03-11-2014
12-11-2013
14- 07-2011
16-03-2012

它需要是:

03-11-2014
12-11-2013
16-03-2012
14-07-2011

推荐答案

使用 STR_TO_DATE 将日期字符串转换为实际日期。

Use STR_TO_DATE to turn your date string into a real date.

SELECT * FROM games 
ORDER BY STR_TO_DATE(release_date, '%d-%m-%Y') DESC

您还可以使用此功能将您的日期重新设置为默认格式,然后更改列数据类型到日期

You can also use this function to refomat your date into the default format and then change the column data type to date.

这篇关于从数据库检索日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆