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.
Comments
Post a Comment