首页 > 解决方案 > Doctrine - 查询字段日期比较

问题描述

我在定义查询时遇到问题。它返回一个空结果。

因此,我尝试编写一个查询,如果数据库字段lastVerification(DateTime 字段)晚于 90 天,则返回结果。

它总是返回一个空数组结果。

我的“最佳”尝试:

$endDate = (new \DateTime())->modify('-90 days');
$endDate->format('Y-m-d H:i:s');

$result = $this->getUserRepository()
        ->createQueryBuilder('otp')
        ->select('otp')
        ->where('otp.lastOtpVerification IS NOT NULL')
        ->andWhere("otp.lastOtpVerification >= :end")
        ->setParameter("end", $endDate)
        ->getQuery()
        ->getResult();

标签: phpmysqldoctrine-ormsymfony-3.4

解决方案


推荐阅读