<bdo id='qC79F'></bdo><ul id='qC79F'></ul>

<i id='qC79F'><tr id='qC79F'><dt id='qC79F'><q id='qC79F'><span id='qC79F'><b id='qC79F'><form id='qC79F'><ins id='qC79F'></ins><ul id='qC79F'></ul><sub id='qC79F'></sub></form><legend id='qC79F'></legend><bdo id='qC79F'><pre id='qC79F'><center id='qC79F'></center></pre></bdo></b><th id='qC79F'></th></span></q></dt></tr></i><div id='qC79F'><tfoot id='qC79F'></tfoot><dl id='qC79F'><fieldset id='qC79F'></fieldset></dl></div>

  1. <legend id='qC79F'><style id='qC79F'><dir id='qC79F'><q id='qC79F'></q></dir></style></legend>
  2. <tfoot id='qC79F'></tfoot>

    1. <small id='qC79F'></small><noframes id='qC79F'>

      Symfony2 日期时间查询生成器

      Symfony2 datetime queryBuilder(Symfony2 日期时间查询生成器)

        <tbody id='szy6Y'></tbody>
    2. <small id='szy6Y'></small><noframes id='szy6Y'>

      <legend id='szy6Y'><style id='szy6Y'><dir id='szy6Y'><q id='szy6Y'></q></dir></style></legend>

      <tfoot id='szy6Y'></tfoot>
    3. <i id='szy6Y'><tr id='szy6Y'><dt id='szy6Y'><q id='szy6Y'><span id='szy6Y'><b id='szy6Y'><form id='szy6Y'><ins id='szy6Y'></ins><ul id='szy6Y'></ul><sub id='szy6Y'></sub></form><legend id='szy6Y'></legend><bdo id='szy6Y'><pre id='szy6Y'><center id='szy6Y'></center></pre></bdo></b><th id='szy6Y'></th></span></q></dt></tr></i><div id='szy6Y'><tfoot id='szy6Y'></tfoot><dl id='szy6Y'><fieldset id='szy6Y'></fieldset></dl></div>
          <bdo id='szy6Y'></bdo><ul id='szy6Y'></ul>
                本文介绍了Symfony2 日期时间查询生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 Symfony2 项目中有 2 个 DateTime 类.我有实体 Stat,其中有 $date 属性.

                I have 2 DateTime classes in Symfony2 project. I have entity Stat, in which have $date property.

                /**
                 * @ORMColumn(type="date", length="11")
                 */
                protected $date;
                

                我必须使用 createQueryBuilder 中的 DateTime 对象进行查询.我怎样才能做到这一点 ?例如:

                I have to make queries using DateTime objects in createQueryBuilder. How can i do that ? For example:

                $date_from = new DateTime('2012-02-01');
                $date_to = new DateTime('2012-02-15');
                

                我需要从 $date_from 和 $date_to 之间的表 stats(实体 Stat)中获取所有行.我应该如何使用 createQueryBuilder 编写查询?我当前的代码是:

                I need to get all rows from table stats (entity Stat) between $date_from and $date_to. How should i write my query with createQueryBuilder ? My current code is:

                $qb = $em->createQueryBuilder();
                $query = $qb->select('s')
                            ->from('ACMEMyBundleEntityStat', 's')
                            ->where('s.date >= :date_from')
                            ->andWhere('s.date <= :date_to')
                            ->setParameter('date_from', $date_from)
                            ->setParameter('date_to', $date_to)
                            ->getQuery();
                

                推荐答案

                本杰明的回答是正确的,但缺少一个细节.这是正确的做法:

                Benjamin's answer is correct, but it lacks one detail. This is the correct way to do it:

                $qb->andWhere($qb->expr()->between('s.date', ':date_from', ':date_to'));
                

                但是要设置参数,我需要这样做:

                But to set parameters, I need to do like this:

                $qb->setParameter('date_from', $date_from, DoctrineDBALTypesType::DATETIME);
                $qb->setParameter('date_to', $date_to, DoctrineDBALTypesType::DATETIME);
                

                如果我省略 DATETIME 类型,我会收到以下错误(请参阅 这里):

                If I omit the DATETIME types, I get the following error (see here):

                DateTime 类的对象无法转换为字符串

                Object of class DateTime could not be converted to string

                我正在使用 Doctrine DBAL 2.0.5,这种行为可能在更高版本的 Doctrine 中有所改变.

                I am using Doctrine DBAL 2.0.5, this behaviour might have changed in later versions of Doctrine.

                这篇关于Symfony2 日期时间查询生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                <small id='umeHu'></small><noframes id='umeHu'>

                <legend id='umeHu'><style id='umeHu'><dir id='umeHu'><q id='umeHu'></q></dir></style></legend>

                  <bdo id='umeHu'></bdo><ul id='umeHu'></ul>
                  • <tfoot id='umeHu'></tfoot>

                    <i id='umeHu'><tr id='umeHu'><dt id='umeHu'><q id='umeHu'><span id='umeHu'><b id='umeHu'><form id='umeHu'><ins id='umeHu'></ins><ul id='umeHu'></ul><sub id='umeHu'></sub></form><legend id='umeHu'></legend><bdo id='umeHu'><pre id='umeHu'><center id='umeHu'></center></pre></bdo></b><th id='umeHu'></th></span></q></dt></tr></i><div id='umeHu'><tfoot id='umeHu'></tfoot><dl id='umeHu'><fieldset id='umeHu'></fieldset></dl></div>
                        <tbody id='umeHu'></tbody>