I’m trying to write a query in Doctrine that will return records added within a certain numbr of days, I have this line in my query but doesn’t work as expected:
$q->andWhere('g.date_added >= ?', array(strtotime('-'.$recent_interval.' day')));
date_added is a mySQL timestamp.
recent_interval is number of days.
I am using Doctrine-1.2.4 with Zend Framework 1.11.7
Appreciate the help.
The format of a MySQL timestamp is
YYYY-MM-DD HH:MM:SS. You’re comparing it with a UNIX timestamp which is a number returned fromstrtotime().You need to convert the UNIX timestamp into a MySQL timestamp first to make it work.
To format a UNIX timestamp, you can make use of the PHP
date()function. The format isY-m-d H:i:s.Example: