php - Get records of all months in symfony -


this question has answer here:

i developing web application using symfony framework.i want fetch records database of months.i dont know how write query fetching records jan december. code:

$totalsearchesbyadminmonth = $em->createquerybuilder()     ->select('count(searchhistory.id) totalsearchesbyadmin')     ->from('drpadminbundle:log',  'searchhistory')      ->where('searchhistory.last_updated :last_updated')     ->setparameter('last_updated',$months.'-%')         ->andwhere('searchhistory.event = :event')     ->setparameter('event','admin_search')             ->getquery()         ->getarrayresult(); 

please help.

assuming searchhistory.last_updated datetime field , $month number of months want search.

$start = new \datetime(); $start->sub(new \dateinterval("p{$months}m");  $totalsearchesbyadminmonth = $em->createquerybuilder() ->select('count(searchhistory.id) totalsearchesbyadmin') ->from('drpadminbundle:log',  'searchhistory')  ->where('searchhistory.last_updated between :last_updated_start , :last_updated_end') ->setparameter('last_updated_start',$start)    ->setparameter('last_updated_end',new \datetime())     ->andwhere('searchhistory.event = :event') ->setparameter('event','admin_search')         ->getquery()     ->getarrayresult(); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -