SQL仅等于日和月不等于年 [英] SQL Only equal to day and month not year
问题描述
所以我该怎么做: SELECT username FROM table_name WHERE birthday ='$ birthday'
?
$ birthday从表单获取其数据,其中输入的例子是:2002-02-02。如果用户有这个生日,它会回应出来。但问题在于它与年度进行核对,而且我试图只得到月和日,而不是年。
我尝试过(EXACT(MONTH FROM ...),但没有让它工作,我还缺少什么?
您可以执行某些,例如
SELECT username FROM table_name
WHERE MONTH(birthday)= MONTH('$ birthday')
AND DAY(birthday)= DAY('$ birthday')
I have a database where users stores their birthday. y-m-d, and Im trying to get every user that has the same birthday. But the year can be difference between each user.
So how do I turn this: SELECT username FROM table_name WHERE birthday='$birthday'
to a working script?
$birthday gets its data from a form, where the inputs is example: 2002-02-02. And if users have this birthday its echo it out. But the problem is that it checks with the year, and Im trying to only get month and day, not year.
I have tried with (EXACT(MONTH FROM ...) but didnt get it to work. What am I missing?
You can do something like
SELECT username FROM table_name
WHERE MONTH(birthday)=MONTH('$birthday')
AND DAY(birthday)=DAY('$birthday')
这篇关于SQL仅等于日和月不等于年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!