简体   繁体   English

ZF2使用日期时间列的DATE()查询WHERE子句

[英]ZF2 Query WHERE clause with DATE() for datetime column

I have a column with datetime data type and I want to build a SQL query in Zend Framework2 which compare date part with user input date. 我有一列具有datetime数据类型的列,我想在Zend Framework2中构建一个SQL查询,该查询将日期部分与用户输入日期进行比较。

Need to build similar part as DATE(datetime column) = '2014-09-16' with; 需要建立与DATE(datetime column)='2014-09-16'类似的部分; $select->where(); $选择 - >其中();

would be very grateful if someone could help on this. 如果有人可以提供帮助,将不胜感激。

Use like this: 像这样使用:

$date = '2014.05.24';
$select->where('date(expecting_date) = "'.$date.'"');

You should use predicate expression for these kind of conditions, like : 对于此类条件,您应使用谓词表达式,例如:

$select = new \Zend\Db\Sql\Select(table name);
$select->where(new \Zend\Db\Sql\Predicate\Expression('DATE(datetime) = ?', '2014-09-16'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM