How to compare dates in validation? How to compare dates in validation? symfony symfony

How to compare dates in validation?


I've eventually solved it using expressions like so:

     /**     * @var \Datetime     * @Assert\Type(     *      type = "\DateTime",     *      message = "vacancy.date.valid",     * )     * @Assert\GreaterThanOrEqual(     *      value = "today",     *      message = "vacancy.date.not_today"     * )     */    private $startdate;    /**     * @var \Datetime     * @Assert\Type(     *      type = "\DateTime",     *      message = "vacancy.date.valid",     * )     * @Assert\GreaterThanOrEqual(     *      value = "today",     *      message = "vacancy.date.not_today"     * )     * @Assert\Expression(     *     "this.getEnddate() >= this.getStartdate()",     *     message="vacancy.date.not_more_than"     * )     */    private $enddate;


Use strtotime
You can convert the date format to timestap and then compare them both