N
N
NkDev2022-04-07 10:37:24
PHP
NkDev, 2022-04-07 10:37:24

How to validate a date in Symfony so that it is not your current date?

The following json is sent to the server from the client:

{
    "birthDate": "12.12.2023"
}


I need to check that the incoming date is less than the current one. Simfony framework. I have this now:

new Assert\Collection([
    'birthDate' => [
        new Assert\DateTime("d.m.Y"),
        new Assert\LessThan(['value'=>'today', 'message'=>"Error!"]),
   ]
]);


However, this code doesn't work. I also tried the option where I change the type from string to new DateTime. Still doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Derepko, 2022-04-07
@NkDev

https://symfony.com/doc/current/reference/constrai...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question