Select entries between dates in doctrine 2(在学说 2 中选择日期之间的条目)
本文介绍了在学说 2 中选择日期之间的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会因为这个我没有得到修复的最小错误而发疯.我想在两天之间选择条目,下面的例子说明了我所有的失败:
I will go insane with this minimal error that I'm not getting fix. I want to select entries between two days, the examples below ilustrate all my fails:
选择 1.
$qb->where('e.fecha > ' . $monday->format('Y-m-d'));
$qb->andWhere('e.fecha < ' . $sunday->format('Y-m-d'));
结果(0 个条目):
SELECT r0_.id_reservacion AS id_reservacion0, r0_.fecha AS fecha1, r0_.cliente AS cliente2
FROM reservacion r0_
WHERE (r0_.fecha > 2012 - 07 - 16) AND (r0_.fecha < 2012 - 07 - 22)
选择 2
$qb->add('where', 'e.fecha between 2012-01-01 and 2012-10-10');
结果(0 个条目):
SELECT r0_.id_reservacion AS id_reservacion0, r0_.fecha AS fecha1, r0_.cliente AS cliente2
FROM reservacion r0_ WHERE r0_.fecha
BETWEEN 2012 - 01 - 01 AND 2012 - 10 - 10
这是我的当前条目表:
id fecha cliente
1 2012-07-16 00:00:00 2
2 2012-07-16 13:00:00 4
3 2012-07-22 23:00:00 4
编辑 1
为了评估sql避免疑惑,我运行了这个查询:
Edit 1
In order to evaluate the sql to avoid doubts, I ran this query:
$qb->where('e.fecha > ' . $sunday->format('Y-m-d'));
结果(3 个条目):
SELECT r0_.id_reservacion AS id_reservacion0, r0_.fecha AS fecha1, r0_.cliente AS cliente2
所以,看起来sql不是问题.FROM 保留 r0_哪里 r0_.fecha > 2012 - 07
So, looks like the sql is not the problem. FROM reservacion r0_ WHERE r0_.fecha > 2012 - 07
推荐答案
你可以...
$qb->where('e.fecha BETWEEN :monday AND :sunday')
->setParameter('monday', $monday->format('Y-m-d'))
->setParameter('sunday', $sunday->format('Y-m-d'));
或者……
$qb->where('e.fecha > :monday')
->andWhere('e.fecha < :sunday')
->setParameter('monday', $monday->format('Y-m-d'))
->setParameter('sunday', $sunday->format('Y-m-d'));
这篇关于在学说 2 中选择日期之间的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:在学说 2 中选择日期之间的条目


基础教程推荐
猜你喜欢
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01