Reputation: 357
My current date is 1/10/2015. If I give sql query in codeigniter as below, It also gives date of like, 1/10/2014,1/10/2013..etc.
So where I going wrong?
Sql query in codeigniter:
function get_birthdate()
{
$this->db->select('fullname as name,avatar,birth_date,user_id',FALSE);
$this->db->from('fx_account_details',FALSE);
$this->db->where('MONTH( birth_date ) = MONTH( CURDATE( ) )
AND DAY( birth_date ) = DAY( CURDATE( ) )
OR (DAY( LAST_DAY( birth_date ) ) =29
AND DAY( birth_date ) =29
AND DAY( LAST_DAY( CURDATE( ) ) ) =28)');
// $this->db->get();
// echo $this->db->last_query();exit;
return $this->db->get()->result();
}
Upvotes: 0
Views: 61
Reputation: 357
I accept David's answer. Also I got my mistake that I solved it. Here is the another answer.
function get_birthdate()
{
$this->db->select('fullname as name,avatar,birth_date,user_id',FALSE);
$this->db->from('fx_account_details',FALSE);
$this->db->where('birth_date = CURDATE()
AND MONTH( birth_date ) = MONTH( CURDATE( ) )
AND DAY( birth_date ) = DAY( CURDATE( ) )
OR (DAY( LAST_DAY( birth_date ) ) =29
AND DAY( birth_date ) =29
AND DAY( LAST_DAY( CURDATE( ) ) ) =28)');
return $this->db->get()->result();
}
Upvotes: 0
Reputation:
Try this may be help:
function get_birthdate()
{
$this->db->select('fullname as name,avatar,birth_date,user_id',FALSE);
$this->db->from('fx_account_details',FALSE);
$this->db->where('YEAR( birth_date ) = YEAR( CURDATE( ) AND MONTH( birth_date ) = MONTH( CURDATE( ) )
AND DAY( birth_date ) = DAY( CURDATE( ) )
OR (DAY( LAST_DAY( birth_date ) ) =29
AND DAY( birth_date ) =29
AND DAY( LAST_DAY( CURDATE( ) ) ) =28)');
// $this->db->get();
// echo $this->db->last_query();exit;
return $this->db->get()->result();
}
Upvotes: 2