Current date in MySQL WHERE clause

后端 未结 1 931
醉梦人生
醉梦人生 2021-01-24 13:05

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:

$         


        
相关标签:
1条回答
  • 2021-01-24 13:26

    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);
    

    0 讨论(0)
提交回复
热议问题