How to compare DateTime in Extbase repository

余生颓废 提交于 2019-12-23 08:27:15

问题


I try to compare the start date of an event with the current date in order to only display the next events. This is my try in the eventRepository:

public function findNext() {
    $query = $this->createQuery();
    $query->matching(
        $query->greaterThanOrEqual('datum_beginn', new \DateTime('midnight'))
    );
    return $query->execute();
}

But the result is not as expected. This is the resulting query:

SELECT events.* FROM events WHERE events.datum_beginn >= 1413669600 AND ...

As you can see the DateTime is converted to a timestamp. How can I either use MySQL NOW() in the query OR use DateTime properly?


回答1:


Use string value of the date:

public function findNext() {
    $query = $this->createQuery();
    $date = new \DateTime('midnight');
    $query->matching(
        $query->greaterThanOrEqual('datum_beginn', $date->format('Y-m-d H:i:s'))
    );

    return $query->execute();
}


来源:https://stackoverflow.com/questions/26451312/how-to-compare-datetime-in-extbase-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!