I'm looking for the right zf2 syntax to select timestamps / timeranges from the database. I know how to make where statements. However it seems that greaterThan() and lessThan() are not working with timestamps/datetime:
where = new Where();
$where->lessThan("datecolumn",$vardate);
I want to select all records older than 2 hours. so whats the right way to select date with 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:
$selectRecords = $this->tableGateway->getSql()->select();
$selectRecords->columns(array('id'))
->where->greaterThanOrEqualTo('dateColumn', $startDate)
->lessThanOrEqualTo('dateColumn', $endDate)
; $resultSet = $this->tableGateway->selectWith($selectRecords);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.