D
D
Dobroe3lo2021-06-23 17:07:56
Doctrine ORM
Dobroe3lo, 2021-06-23 17:07:56

How to write current date in sql (createquerybuilder)?

How to write current date in sql (createquerybuilder) symfony 5?
I try the following options, but they do not work. (datetime type)

$this->createQueryBuilder('t')
            ->update()
            ->set('t.status', 1)
            ->set('t.ok_date',  new \DateTime('now'))
            ->where('t.id = :t_id')
            ->setParameter('t_id', $t_id)

$this->createQueryBuilder('t')
            ->update()
            ->set('t.status', 1)
            ->set('t.ok_date',  'NOW()')
            ->where('t.id = :t_id')
            ->setParameter('t_id', $t_id)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2021-06-23
@Dobroe3lo

1. ->set('t.ok_date', new \DateTime('now')->format('Ymd h:i:s'))
2. ->setParameter('ok_date', new \DateTime('now '), \Doctrine\DBAL\Types\Type::DATETIME)
3. Why not do it with an object? What for for such nonsense to climb in qb?

N
Nikita Pushkar, 2021-07-02
@NickPush

I usually create a variable
$now = new \DateTime(date('Ymd H:i:s'));
and then I stick this $now in the right place

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question