Php 日期年份出错
我现在的日期是2015年1月10日。如果我在codeigniter中给出sql查询,如下所示,它还会给出日期,如2014年10月1日、2013年10月1日……等等 那我错在哪里呢 codeigniter中的Sql查询:Php 日期年份出错,php,mysql,codeigniter,Php,Mysql,Codeigniter,我现在的日期是2015年1月10日。如果我在codeigniter中给出sql查询,如下所示,它还会给出日期,如2014年10月1日、2013年10月1日……等等 那我错在哪里呢 codeigniter中的Sql查询: function get_birthdate() { $this->db->select('fullname as name,avatar,birth_date,user_id',FALSE); $this->db->
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();
}
尝试以下方法可能会有所帮助:
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();
}
我接受大卫的回答。我也犯了我的错误,我解决了它。这是另一个答案
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();
}
你想让它做什么?“错”在哪里?WHERE条款中没有将年份限制为当前年份(或其他年份)。