[英]zf2 db sql where datetime before two ours ago
I'm looking for the right zf2 syntax to select timestamps / timeranges from the database. 我正在寻找正确的zf2语法以从数据库中选择时间戳/时间范围。 I know how to make where statements.
我知道如何在哪里发表声明。 However it seems that greaterThan() and lessThan() are not working with timestamps/datetime:
但是,似乎bigThan()和lessThan()在时间戳/日期时间上不起作用:
where = new Where();
$where->lessThan("datecolumn",$vardate);
I want to select all records older than 2 hours. 我想选择所有早于2小时的记录。 so whats the right way to select date with zend framework 2?
那么使用zend Framework 2选择日期的正确方法是什么?
Thx, I really appreciate your help 谢谢,非常感谢您的帮助
This works fine (just a sample) - 效果很好(只是一个示例)-
$select = new Select('album');
$created = date('Y-m-d H:i:s', strtotime("-2 hours"));
$where = new Where();
$where->lessThanOrEqualTo('created', $created);
$select->where($where);
$resultSet = $this->tableGateway->selectWith($select);
Try something like this in your mapper method: 在您的mapper方法中尝试以下操作:
$selectRecords = $this->tableGateway->getSql()->select();
$selectRecords->columns(array('id'))
->where->greaterThanOrEqualTo('dateColumn', $startDate)
->lessThanOrEqualTo('dateColumn', $endDate)
; ; $resultSet = $this->tableGateway->selectWith($selectRecords);
$ resultSet = $ this-> tableGateway-> selectWith($ selectRecords);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.