通过DESC的DateTime -Immutable排序查找最后一个条目

发布于 2025-02-10 21:14:44 字数 592 浏览 1 评论 0原文

如何在数据库中有最后一个条目? 我想拥有今年的最后一个条目(2022,2023 ...),

我已经用$ YEAR-格式('y')进行了测试,但是结果始终是[ ](空数组)

$column = "numeroDevis";
$year = new DateTimeImmutable('now').

    public function findLastEntryFromThisYear($column, $year)
{

    return $this->createQueryBuilder('d')
        ->where('d.createdAt = :year')
        ->andWhere('d.'.$column.' IS NOT NULL')
        ->setParameter('year', $year)
        ->orderBy('d.'.$column , 'DESC')
        ->setMaxResults(1)
        ->getQuery()
        ->getResult()
    ;
}

How can I have the last entry in my database?
I want to have the last entry from this year (2022,2023...)

I have tested with $year->format('Y'), but the result is always [] (empty array)

$column = "numeroDevis";
$year = new DateTimeImmutable('now').

    public function findLastEntryFromThisYear($column, $year)
{

    return $this->createQueryBuilder('d')
        ->where('d.createdAt = :year')
        ->andWhere('d.'.$column.' IS NOT NULL')
        ->setParameter('year', $year)
        ->orderBy('d.'.$column , 'DESC')
        ->setMaxResults(1)
        ->getQuery()
        ->getResult()
    ;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文