SQL仅等于日和月不等于年 [英] SQL Only equal to day and month not year

查看:129
本文介绍了SQL仅等于日和月不等于年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户存储他们的生日的数据库。 y-m-d,我试图让每一个生日相同的用户。但是每年的用户可能会有所差异。



所以我该怎么做: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆