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

Flerex's avatar

Slashes on date format in Validator not working

I'm trying to validate a date in d/m/Y format, like for example 20/10/1990. But, for some reason the following code does not pass:

$validator = Validator::make(['my-date' => '20/10/1990'], [
	'my-date' => ['date', 'date_format:d/m/Y']

$validator->fails(); // true, should be false

However, the following code indeed does work, and I'm only changing the slashes for dashes.

$validator = Validator::make(['my-date' => '20-10-1990'], [
	'my-date' => ['date', 'date_format:d-m-Y']

$validator->fails(); // false

Any idea why this is not working as expected?

0 likes
2 replies
click's avatar
click
Best Answer
Level 35

That is because you have 2 validators: date and date_format they won't work well together. See the documentation: https://laravel.com/docs/master/validation#rule-date-format

It fails because d/m/Y is not one of the default formats, because the default for / notation is m/d/Y that is probably why it fails on the date validator.

conclusion: remove the date validator and only keep the date_format

1 like
Flerex's avatar

I was even warned in the documentation. I must've missed that. Yikes!

Thank you very much!

Please or to participate in this conversation.