I'm trying to compare dates in my validation. The documentation says it's possible but It's not documented. I'm using annotations and I want one date to be later that the other. How do I do this?
Try using CompareTwoValues; it is multi-purpose. CompareDates(Date1+"T000000. 000 GMT", Date2+"T000000.
you can use the DATEVALUE(datetime field) function to extract the date part from the date/time field and then compare it with values like TODAY() - 1 or any specific date value ... you can use DATE(year, month, day) function to build a static date to compare..
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With