Reputation: 996
I have a SQL-table where I have records of my clients such as first name, last name, date of birth etc. Now I try to find all clients by date of birth (for cron, sending holiday and birthday greetings). Therefore, I need to find all existing clients with a specific date of birth.
For example:
In the SQL table I have a few records with these birth dates.
+==================+
| Date_of_birthday |
====================
| 1981-06-30 |
--------------------
| 1972-06-30 |
--------------------
| 1966-10-07 |
====================
Now I need to return all clients who were born on June 30th.
I tried:
SELECT * FROM `table`
WHERE DATE(Date_of_birthday) = '####-06-30';
But my pattern does not seem to work properly, it doesn't return any lines.
The hashtag character '#' should represent any numeric character, but it doesn't work.
Where is my mistake? Or do I have to write the SQL query differently?
Upvotes: 0
Views: 1401
Reputation: 141
This query should do:
select *
from YourTable
where datepart(day, date_birth) = 30
and datepart(month, date_birth) = 06
Upvotes: 2
Reputation: 164099
With DATE_FORMAT()
:
SELECT * FROM `table`
WHERE DATE_FORMAT(Date_of_birthday,'%m-%d') = '06-30';
Upvotes: 2