簡體   English   中英

在mysql / symfony2中比較日期

[英]Comparing dates in mysql / symfony2

我一直在尋找,還有一些相關的問題,但是沒有人給我我需要的答案。 我有一個帶有日期字段的實體,我需要選擇從現在起7天以上的實體:

$query = $repository->createQueryBuilder('rf')
                    ->where('rf.sendDate >='.new \DateTime('-7 days'))
                    ->getQuery();

我收到此錯誤:

Catchable Fatal Error: Object of class DateTime could not be converted to string

我想知道的是,當在實體rf.sendDate定義為DateTime對象時,為什么假設rf.sendDate是字符串? 我該如何比較?

任何解釋都非常感謝。

您應該為此使用參數:

    $query = $repository->createQueryBuilder('rf')
            ->where('rf.sendDate >= :ts')
                ->setParameter('ts', new \DateTime('-7 days'))
            ->getQuery();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM