Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

richard's avatar

Laravel Date Validation

How do I validate a date in such a way that it only accepts a date which is same asa given date, or older than that.

 $rules = [
    'start_at'      => 'required|date|date_format:Y-m-d|after:yesterday',
    'end_at'        => 'required|date|date_format:Y-m-d|after:xxxx',
];

xxxx represent the validation I want to perform. I want to be able to start a task today or any day in the future and be able to set the ending date to the same as starting date or older than that.

Logically, the ending date must be greater or equal to the starting date.

0 likes
8 replies
code_chris's avatar

Can you just do:

    'end_at'        => 'required|date|date_format:Y-m-d|after:start_at',

Otherwise I think you can put the start_at date in a variable and pass that in instead.

2 likes
richard's avatar

Well, that won't work the way I want. It will not allow me to set the end date to be the same as start date. It will only accepts dates older than start_date.

bestmomo's avatar

End that ?

 $rules = [
    'start_at'      => 'required|date|date_format:Y-m-d|before:end_at',
    'end_at'        => 'required|date|date_format:Y-m-d|after:start_at',
];
1 like
code_chris's avatar

Well you could make a new variable with the start_at - 1 day and pass that in instead, perhaps not ideal but it should work fine.

atishrajput's avatar

'required|date_format:Y-m-d|after:tomorrow'

you should use either date or date_format not both together

if you want to validate the given date will be greater than current date then you should use after:tomorrow instead of after:today

1 like
atishrajput's avatar

How do I validate a date in such a way that it only accepts a date which is same asa given date, or older than that.

'required|date_format:Y-m-d|before:xxxx'

1 like

Please or to participate in this conversation.