Update entity with query criteria : Incorrect date value

I wrote doctrine query builder for updating entity where field endDate is null.

public function update(int $clientId, DateTime $endDate): void
{
    $qb = $this->createQueryBuilder('s');

    $qb ->update(User::class, 's')
        ->set('s.endDate', $endDate->format("Y-m-d"))
        ->where('s.clientId =:clientId')
        ->andWhere($qb->expr()->andX(
            $qb->expr()->isNotNull('s.endDate'),
            $qb->expr()->gt('s.endDate', $endDate->format("Y-m-d"))
        ))
        ->setParameter('clientId', $clientId)
        ->getQuery()
        ->execute();
}

I don’t know where and why this error is coming from:

Invalid datetime format: 1292 Incorrect date value: ‘1995’ for column ‘end_date’ at row 1"

I tried basically every ->format example. It work’s on other methods..

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *