mysqlzend-framework2zend-dbzend-db-tablezend-db-select

zf2 db sql where datetime before two ours ago


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


Solution

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