Veljko Stefanovic
Veljko Stefanovic

Reputation: 511

Date/Time validation with specific format

I had problem validating date-time string in Laravel.

Here is a rule:

'time_in' => 'date_format:dd/MM/yyyy HH:mm',

And here is an image of how it's actually written: datum

By all account, it should work. What gives?

Upvotes: 0

Views: 2220

Answers (2)

Khaldoun Al Halabi
Khaldoun Al Halabi

Reputation: 153

date_format:format

The field under validation must match the given format. You should use either date or date_format when validating a field, not both. This validation rule supports all formats supported by PHP's DateTime class.

check laravel docs about validation rules : https://laravel.com/docs/9.x/validation#rule-date-format.

Upvotes: -1

PunyFlash
PunyFlash

Reputation: 1086

You're describing format in a wrong way. Should be:

'time_in' => 'date_format:d/m/Y H:i',

Upvotes: 1

Related Questions