MySQL WHERE子句中的当前日期 [英] Current date in MySQL WHERE clause

查看:1041
本文介绍了MySQL WHERE子句中的当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想要从当前日期开始的日期.我如何在CodeIgniter中问这个问题? "end_date"是DATETIME(Y-m-d H:i:s).

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->db->select("DATE(end_date) as my_end_date", FALSE);
$this->db->where('my_end_date >', date());
$q = $this->db->get('tblTest');

推荐答案

您需要在PHP中格式化日期使其采用MySQL想要的格式.

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

尝试一下:

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

您还可以使用MySQL的 NOW() .

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

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

<罢工> 如果要使用别名my_end_date,则可以使用HAVING代替WHERE.

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子句中的当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆