在教义中选择日期之间的条目2 [英] Select entries between dates in doctrine 2

查看:134
本文介绍了在教义中选择日期之间的条目2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会疯狂的这个最小的错误,我没有得到修复。我想在两天之间选择条目,以下示例无效我所有失败:



选择1。

  $ qb-> where('e.fecha>'。$ monday-> format('Ym-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)

strong>

  $ 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以避免疑惑,我运行了这个查询:

  $ qb-> where('e.fecha>'。$ sunday-> format('Ym-d')); 

结果(3条目):

  SELECT r0_.id_reservacion AS id_reservacion0,r0_.fecha AS fecha1,r0_.cliente AS cliente2 

所以,看起来像sql不是问题。
FROM reservacion r0_
WHERE r0_.fecha> 2012 - 07

解决方案

您可以执行...

  $ qb-> where('e.fecha BETWEEN:monday AND:sunday')
- > setParameter ('monday',$ monday-> format('Ym-d'))
- > setParameter('sunday',$ sunday-> format('Ym-d'));

或...

 code> $ qb-> where('e.fecha>:monday')
- > andWhere('e.fecha<:sunday')
- > setParameter 'monday',$ monday-> format('Ym-d'))
- > setParameter('sunday',$ sunday-> format('Ym-d'));


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:

opt 1.

$qb->where('e.fecha > ' . $monday->format('Y-m-d'));
$qb->andWhere('e.fecha < ' . $sunday->format('Y-m-d'));

result (0 entries):

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)

opt 2

$qb->add('where', 'e.fecha between 2012-01-01 and 2012-10-10');

result (0 entries):

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

This is my table with current entries:

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

Edit 1

In order to evaluate the sql to avoid doubts, I ran this query:

$qb->where('e.fecha > ' . $sunday->format('Y-m-d'));

result (3 entries):

SELECT r0_.id_reservacion AS id_reservacion0, r0_.fecha AS fecha1, r0_.cliente AS cliente2 

So, looks like the sql is not the problem. FROM reservacion r0_ WHERE r0_.fecha > 2012 - 07

解决方案

You can do either…

$qb->where('e.fecha BETWEEN :monday AND :sunday')
   ->setParameter('monday', $monday->format('Y-m-d'))
   ->setParameter('sunday', $sunday->format('Y-m-d'));

or…

$qb->where('e.fecha > :monday')
   ->andWhere('e.fecha < :sunday')
   ->setParameter('monday', $monday->format('Y-m-d'))
   ->setParameter('sunday', $sunday->format('Y-m-d'));

这篇关于在教义中选择日期之间的条目2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆