开发者

30 days in Doctrine Symfony

i would like add clause where - max 开发者_JS百科30 days from now.

in database i have timestamp:

2011-08-30 20:29:35

id  | name | date
1   | aaa  | 2011-08-30 20:29:35
2   | vvv  | 2011-08-10 20:29:35
3   | bbb  | 2011-07-10 20:29:35
4   | fff  | 2011-08-14 20:29:35
5   | ddd  | 2011-06-10 20:29:35


$query = Doctrine_Core::getTable('News')->createQuery('a');
$query->addWhere('date ????????');

How can i get all news recent 30 days?


$query->andWhere('date > ?', date('Y-m-d', time() - 60*60*24*30))


MySQL provides another handy solution :

WHERE date > DATE_SUB(NOW(), INTERVAL 30 DAY)

see : http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜