Search code examples
datedoctrine-ormsymfony4

How do I compare the date from the user with the date in the database? in symfony


I use symfony 4.when i compare date i can only compare years as below not days or months. if it is in different months and days in the same year, it shows equal to each other. i want to compare with days, month and years. "p.createdAt" type is datetime

    if (!empty($filter['startDate'])) {
        $qb->andWhere($qb->expr()->gte('p.createdAt',':startDate'))
        ->setParameter('startDate',$filter['startDate']);
    }

Solution

  • I use code like this:

    $qb->andWhere('p.createdAt >= :queryDate')
        ->setParameter('queryDate', $queryDate);
    

    without problem.