在mysql中仅与日期字段进行比较 [英] Compare only day and month with date field in mysql
本文介绍了在mysql中仅与日期字段进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较只有日期和月份与日期字段在mysql?
例如,我在一个表中有日期: 2014-07-10
How to compare only day and month with date field in mysql?
For example, I've a date in one table: 2014-07-10
类似,另一个日期 2000-07-10
在另一个表。
我想比较只有日期和月份在日期字段上相等。
Similarly, another date 2000-07-10
in another table.
I want to compare only day and month is equal on date field.
我尝试过这种格式。但是我无法得到答案
I tried this format. But I can't get answer
select *
from table
where STR_TO_DATE(field,'%m-%d') = STR_TO_DATE('2000-07-10','%m-%d')
where id = "1"
推荐答案
使用DATE_FORMAT:
Use DATE_FORMAT instead:
SELECT DATE_FORMAT('2000-07-10','%m-%d')
产生
07-10
以下是您使用 DATE_FORMAT()
重新编写的查询:
Here's your query re-written with DATE_FORMAT()
:
SELECT *
FROM table
WHERE DATE_FORMAT(field, '%m-%d') = DATE_FORMAT('2000-07-10', '%m-%d')
AND id = "1"
这篇关于在mysql中仅与日期字段进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文