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

unkown.persone's avatar

Date validation in Laravel

Hello,

I want to validate a form request.

'start'       =>  'required|date|date_format:Y-m-d|after:tomorrow',
'end'      =>  'required|date|date_format:Y-m-d|after:start'

Those above are the rules.

My problem is when ever I try to fill the dates with Bootstrap-datepicker it gives me an error. The format is not correct. I already know that the format doesn't match, because Bootstrap-datepicker doesn't allow such format like Y-m-d

My question is:

Can I change the format in the rule so it matches the format of Bootstrap-datepicker's format. Like the following

dd-mm-yyyy

I have used to wrok with HTML5 and the attribute date but unfortunately it doesn't work on Firefox.

The language of the datepicker is also important to me.

Thanks guys.

0 likes
7 replies
Cronix's avatar

which "bootstrap datepicker" are you using? Most allow you to specify the date format.

unkown.persone's avatar

Awesome, I just tried it out. It doesn't work. It seems to be that the validation rule is the problem. I have put the same on the rule and on the Bootstrap-datepicker

yyyy/mm/dd
The start does not match the format yyyy/mm/dd.
Cronix's avatar
Cronix
Best Answer
Level 67

It's probably bc php and that javascript package have different symbols for different date components.

For the datepicker, try what I suggested above yyyy-mm-dd and for the laravel validation rule try Y-m-d. Those should be equivalent.

I'm just suggesting the Y-m-d format bc I assume you're storing this as a date column type in the db.

2 likes

Please or to participate in this conversation.