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

ponnydalen's avatar

Date format validation error

Trying to validate two datefields with Pikday datepicker. Pikaday format is: format: 'D MMM YYYY' When I dd the input request I get this: "22 okt. 2021" (norwegian locale)

Then:

$request->validate([
      'pickup_date' => 'required|date_format:d M. Y',
      'delivery_date' => 'required|date_format:d M. Y',
]);

Gives me this:

"The pickup date does not match the format d M. Y." Is there something about that period after the Y? If so, why is it even there?

Does someone has an explanation why this is happending? Thanks.

0 likes
2 replies
Sinnbeck's avatar

The problem probably comes from d M. Y makes a timestamp with uppercase O in Okt, while your value is okt

This is the validation in laravel

         $format = $parameters[0];

        $date = DateTime::createFromFormat('!'.$format, $value);

        return $date && $date->format($format) == $value;
Sinnbeck's avatar

A better solution might be to set a proper format (YYYY-MM-DD) before sending it to laravel (in js)

Please or to participate in this conversation.