我目前的日期是2015年1月10日。如果我在codeigniter中给出sql查询,如下所示,它也给出了类似的日期,1/10 / 2014,1 / 10 / 2013..etc。
所以我哪里错了?
codeigniter中的SQL查询:
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();
}
答案 0 :(得分:2)
试试这可能有所帮助:
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();
}
答案 1 :(得分:0)
我接受大卫的回答。我也弄错了,我解决了它。这是另一个答案。
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();
}