MySQL在两种日期格式之间转换 [英] MySQL convert between two date format
本文介绍了MySQL在两种日期格式之间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用户将以以下格式输入日期:2017年2月17日
The user will enter the date in this format : 17-Feb-2017
并且mysql db中存储的日期的格式为:2015-02-17 00:00:00
and the date stored in mysql db is in this format : 2015-02-17 00:00:00
我想做的是
SELECT * FROM insurance where DATE_FORMAT(in_date,'%d-%b-%Y') > '17-Feb-2017';
DATE_FORMAT(in_date,'%d-%b-%Y')以以下格式返回日期:2017年2月17日
DATE_FORMAT(in_date,'%d-%b-%Y') return the date in this format : 17-Feb-2017
但是不能正常工作!
有什么建议吗?
推荐答案
将输入也转换为日期类型和列值:
Convert the input to a date type and the column value too:
SELECT * FROM insurance where date(in_date) > STR_TO_DATE('17-Feb-2017','%d-%b-%Y')
有关STR_TO_DATE
和DATE
函数的更多说明,请参见 mysql文档.
请勿将两个值都转换为字符串,因为转换后无法对其进行比较
For more explanation about STR_TO_DATE
and DATE
function see the mysql documentation.
Do not convert both values to string, because you can not compare it after the convertion
这篇关于MySQL在两种日期格式之间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文