Reputation: 181
tbl_user
user_id user_name user_email user_bday
1 steve [email protected] 1970-06-16
2 mark [email protected] 1989-07-12
3 lee [email protected] 1976-05-06
4 grand [email protected] 1986-07-30
5 smith [email protected] 1993-02-17
I want to fetch users who has birthday on month July, Result will be
2 mark [email protected] 1989-07-12
4 grand [email protected] 1986-07-30
I have tried queries like:
get first & last date of month which we need to get result & passed to SQL query like:
SELECT * FROM tbl_user WHERE user_bday >= '07-01' AND user_date_of_birth <= '07-31'
Upvotes: 0
Views: 34
Reputation: 257
Make sure that your column birthday is a date
type, then extract the month from date with the mysql function month(date)
, see example: https://www.w3resource.com/mysql/date-and-time-functions/mysql-month-function.php
Upvotes: 0
Reputation: 886
If the user_bday column is date datatype then try this
SELECT * FROM tbl_user WHERE month(user_bday) = 7
if you want particular year and month then try this
SELECT * FROM tbl_user WHERE month(user_bday) = 7 and year(user_bday) = 2000
Upvotes: 1