mysql时间where格式,MySQL WHERE子句中的当前日期

I only want the dates starting from the current date. How do I ask this in CodeIgniter? "end_date" is a DATETIME (Y-m-d H:i:s).

This isn't working:

$this->db->select("DATE(end_date) as my_end_date", FALSE);

$this->db->where('my_end_date >', date());

$q = $this->db->get('tblTest');

解决方案

You need to format the date in PHP so that it's in the format MySQL wants.

Try this:

$this->db->where('end_date >', date('Y-m-d H:i:s'));

You can also use MySQL's NOW() for this.

$this->db->where('end_date > NOW()', NULL, FALSE);

EDIT: If you want to use the alias my_end_date, you can use HAVING instead of WHERE.

$this->db->having('my_end_date > NOW()', NULL, FALSE);

你可能感兴趣的:(mysql时间where格式)