如何在Extbase存储库中比较DateTime [英] How to compare DateTime in Extbase repository

查看:70
本文介绍了如何在Extbase存储库中比较DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将事件的开始日期与当前日期进行比较,以便仅显示下一个事件.这是我在eventRepository中的尝试:

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 ...

如您所见,DateTime已转换为时间戳.如何在查询中使用MySQL NOW()或正确使用DateTime?

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?

推荐答案

使用日期的字符串值:

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();
}

这篇关于如何在Extbase存储库中比较DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆