MySQL:比较日期字符串? [英] MySQL: Compare date strings?
本文介绍了MySQL:比较日期字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一列是一个字符串,它包含这样的值: 11.05.2012 05:22:12
I have a column which is a string, it holds values like that: 11.05.2012 05:22:12
现在我想得到该列中有日期< = 30.09.2011
的所有行。我试过
Now I want to get all rows that have a date <= 30.09.2011
in that column. I tried
DATE_FORMAT(my_column_with_the_string_date, "%Y-%m-%d") <= '2011-09-30'
但此失败(不返回任何结果)。任何想法?
but this failed (returns no results). Any ideas?
推荐答案
您需要的是 STR_TO_DATE()
函数。
SELECT
*
FROM yourTable
WHERE
STR_TO_DATE(my_column_with_the_string_date, '%d.%m.%Y') <= '2011-09-30'
详细了解此处。
这篇关于MySQL:比较日期字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文