php - Doctrine querybuilder TO_DAYS -


is there equivalent doctrine of sql query?

select tbl_name to_days(now()) - to_days(date_col) <= 30; 

entity has

/** * @var \datetime * @orm\column(type="datetime",nullable=true) */ protected $newstatusdata; 

so, need records condition

"nowdate - newstatusdata =< 30 days" 

update

thanks alok , answer given below

namespace appbundle\entity;  use doctrine\orm\entityrepository;  class questrepository extends entityrepository {     function  getnewquests(){         $query = $this->getentitymanager()             ->createquery('select q appbundle:quest q date_diff(current_date() , q.newstatusdata) >= 30');         $result = $query->getresult();         return $result;     } } 

may you're looking date_diff() dql function. calculate difference in days between given dates.

it accepts 2 arguments of date.

so can query data this,

<?php     $result=$this->getentitymanager()             ->createquery("select en bundle:entityname date_diff(current_date(),en.newstatusdata)>=30")             ->getresult(); ?> 

current_date() returns current date.

http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#dql-functions


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -