在mysql函数之间使用忽略年份 [英] Using between mysql function ignoring year
本文介绍了在mysql函数之间使用忽略年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,我有下面的用户表:
id | name | birthday
1 | nam1 | 1980-06-29
2 | nam2 | 1997-07-08
3 | nam3 | 1997-07-20
假设今天是2012-06-29
Assuming that today is 2012-06-29
我如何获得将在未来15天内庆祝您生日的用户?我已经尝试过了:
How can I get the users who will celebrate your birthdays in the next 15 days? I have tried with this:
select * from users where birthday between '%-06-29' and '%-07-14';
但看起来不是有效的查询.
but looks like is not a valid query.
推荐答案
我认为最安全的方法是将15天的年龄与今天的年龄进行比较:
I think the safest way is to compare their age in 15 days with their age today:
SELECT *
FROM Users
WHERE TIMESTAMPDIFF(YEAR, birthday, CURRENT_DATE + INTERVAL 15 DAY)
> TIMESTAMPDIFF(YEAR, birthday, CURRENT_DATE)
在 sqlfiddle 上查看.
这篇关于在mysql函数之间使用忽略年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文