1

I want to get the data from the DB (my sql) which are all posted for current week. I am using Doctrine ORM, my sql. I think i need to use createQueryBuilder for this but i dont know exactly how to use that for my situation. I tried with the below statement, but didnt worked.

......->createQueryBuilder('t')
        ->where('WEEK(t.dateCreated) = WEEK(CURDATE())')                      
        ->getQuery()
        ->getResult(); 

Please help me on this.

Vinoth Babu
  • 6,724
  • 10
  • 36
  • 55

1 Answers1

1

Well, I don't think those mysql constructions (WEEK,YEAR,MONTH) are currently available unless you use doctrine extensions. There's a post here that talks about that.

If your week starts on Monday and ends on Sunday, another solution could be as follows:

$start_week = date("Y-m-d",strtotime('monday this week'));
$end_week = date("Y-m-d",strtotime('sunday this week'));
......->createQueryBuilder('t')
        ->where('t.dateCreated >= :start')
        ->andWhere('t.dateCreated <= :end')
        ->setParameter('start',$start_week)                      
        ->setParameter('end',$end_week)
        ->getQuery()
        ->getResult(); 
Community
  • 1
  • 1
acontell
  • 6,792
  • 1
  • 19
  • 32