Alejandro
Alejandro

Reputation: 49

Extract only the month in a query CodeIgniter

I want to make a query where I get people birthday's in a current month, I have problems with MONTH() it does not work for me, the date format in the database is: 04/18/1990, and I want to compare if the month current date('m') is equal to the month of the database.

Any suggestions?

Upvotes: 0

Views: 2771

Answers (3)

ScaisEdge
ScaisEdge

Reputation: 133370

could be you have some convertion issue try using

 select  month(str_to_date(my_col, '%m/%d/%Y'))
 from my_table  
 where   month(str_to_date(my_col, '%m/%d/%Y')) = month(now())

Upvotes: 0

madara uchiha
madara uchiha

Reputation: 212

you can try this one

SELECT * FROM table_name where extract(month from BirthDate) = date("m");

where date("m") return current month and BirthDate is column name in which you have stored birthdate.

Upvotes: 1

M.Hemant
M.Hemant

Reputation: 2355

Try this

"select  month(str_to_date(birthdate), '%Y/%m/%d')
from users  
where month(str_to_date(birthdate), '%Y/%m/%d') = '$month'"

Here, i m assuming your delimeter is '/', Please set your delimeter according to your string date i.e 2013/05/04 or 2013,05,04 or 2013-05-04

Upvotes: 0

Related Questions