How to compare two timestamps for a duration longer than a certain time period zend-db

zend-db

#1

I want to compare two timestamps (which are in the format of:YYYY-MM-DD HH:MM:SS.SSSSSS example: 2018-07-11 06:38:32.916000) to return all the entries where the tim difference between the two is more than a second.

Here is what I tried:

$where = new Zend\Db\Sql\Where();
//UPDATE and BIRTH are both timestamps
$where->greaterThan(‘UPDATE - BIRTH’, 1);

Yeah… that didnt work. What would be the way to go about this?


#2

you can use native SQL function, for example, if you use MySQL, you should can do:

use Zend\Db\Sql\Where;

$where = new Where();
$where->expression('TIMESTAMPDIFF(SECOND, BIRTH, UPDATE) > ?', 1);