0

The "start" is a dateTime. I'm trying to get all rows that have "start" = Today without considering the hours and mins. This what I did so far. Only events with this form 'Y-m-d 00:00:00' are selected

$em = $this->getDoctrine()->getManager();
    $onthisday = $em->createQuery('
        SELECT e
        FROM ECMEventBundle:Events e
        WHERE e.start = CURRENT_DATE()

        AND e.eventcreator = :userId'
    )->setParameter ( 'userId', $user->getId () );

    $todayEvent = $onthisday->getResult();

Any response will be appreciated.

Akram
  • 174
  • 3
  • 12
  • You need to register a [*date function*](http://stackoverflow.com/questions/13272224/use-a-date-function-in-a-where-clause-with-dql) first for doctrine to understand then use `WHERE DATE(e.start)=CURRENT_DATE()` – M Khalid Junaid Jun 19 '14 at 16:41

1 Answers1

1

you can use php DateTime class:

$myDate = new \DateTime();

$em = $this->getDoctrine()->getManager();
    $onthisday = $em->createQuery('
        SELECT e
        FROM ECMEventBundle:Events e
        WHERE e.start > :myDate

        AND e.eventcreator = :userId'
    )->setParameter ( 'userId', $user->getId () )
    ->setParameter ( 'myDate', $myDate->format('Y-m-d 0:0:0') );
mohsenJsh
  • 2,048
  • 3
  • 25
  • 49