Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .
Closed 8 years ago.
Improve this question
I would like to get the names from a user table if the users' birthday is today.
User table
name | date of birth
------+-----------------
name1 | 20/05/1991
name2 | 05/01/1995
name3 | 05/01/1991
If I supply: 05/01/2015
as parameter, it should display name2
and name3
.
Can anyone tell me the SQL query required for filtering the results by the date parameter.
2条答案
按热度按时间vmpqdwk31#
This query should work for you:
Here is a SQLFiddle with the query based on your sample data.
My initial answer was incorrect because it was actually looking for the same date between
GETDATE()
with theDATE OF BIRTH
which is incorrect if you are looking for people who have birthdays today (because birthdays are not dependant on year, but on month and day).flvtvl502#
For getting list for a range of dates: