MySQL ORDER BY Date字段,它不是日期格式 [英] MySQL ORDER BY Date field which is not in date format

查看:63
本文介绍了MySQL ORDER BY Date字段,它不是日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字段,其日期格式为DD/MM/YYYY,我需要按此字段对结果DESC进行排序,但是将其保存为VARCHAR,因此无法更改.有解决方法吗?

I have a field containing dates in this format DD/MM/YYYY and I need to order the results DESC by this field, but it is saved as a VARCHAR and I cannot change this. Is there a workaround?

我真的没有办法更改字段类型,所以请不要像我已经知道的那样说这是一种不好的方法.我只想知道是否有可能.

There really is no way for me to change the field type so please don't say this is a bad way to do this as I already know. I just need to know if it is possible.

感谢您的任何帮助和建议.

Thanks for any help and advice in advance.

推荐答案

您可以通过以下方式实现,

You can do it by the following way,

SELECT ...
FROM ...
ORDER BY STR_TO_DATE(yourDate,'%d-%m-%Y') DESC

这篇关于MySQL ORDER BY Date字段,它不是日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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