Reputation: 927
I am using cakephp 2.1 and I have created a table actor(id, first_name, last_name, dob)
.
Where dob is date of birth and having date format as Y-m-d. I would like to fetch the users who have their birthday on perticular month or perticular day. I have tried it but got solution. Please help me do that.
The work is appreciable.
Upvotes: 0
Views: 110
Reputation: 71
Lets say you want to know who has it's birth day in this month:
$conditions = array(
'Actor.dob LIKE ?' => CakeTime::format("\%-m\%")
);
For today:
$conditions = array(
'Actor.dob LIKE ?' => CakeTime::format("\%-m-d\%")
);
You need to be more clear on what you really need to query.
Upvotes: 1
Reputation: 28705
write your condition like code bellow:
$conditions = array (
'AND' => array (
'MONTH(Actor.dob)' => '12',
'DAY(Actor.dob)' => '1',
'YEAR(Actor.dob)' => '2012',
)
)
Upvotes: 1
Reputation: 14263
if particular month (here i have taken second month of year)
select * from actor where MONTH(dob)='02'
particular day 02.
select * from actor where DAY(dob)='02'
Upvotes: 1