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

adamjhn's avatar

Why appear a validation error saying the date format is invalid?

I have a date field like:

<div class="form-group col-md-6">
    <label for="date">Date</label>
    <div class="input-group date" data-provide="datepicker">
        <input type='text' onkeydown="event.preventDefault()"
               name="date" value="{{ old('date') }}" class="form-control"/>
    </div>
</div>

jQuery:

var date = new Date();
date.setDate(date.getDate());
$(".input-group.date").datetimepicker({
    format: "dd MM yyyy - hh:ii",
    autoclose: true,
    todayBtn: true,
    minuteStep: 5,
    startDate: date,
});

To insert in db first I have this code to valdiate:

     'date' => 'nullable|date_format:"d F Y - H:i"',

Then to insert:

        'date' => (isset(
$request->date)) ? Carbon::createFromFormat('d F Y - H:i', $request->date) : null,

But even if the user introduce a date using the datetime picker it shows always a validation error saying that the format of the date is invalid. Do you know why?

The "dd(date('d F Y - H:i'));" shows "22 July 2018 - 18:37" (shows in en).

The "$request->all()" shows "date" => "22 Juli 2018 - 19:50" (shows in german).

0 likes
2 replies
adamjhn's avatar

Thanks, I change in the server to " 'date' => 'nullable|date_format:"j-m-y - H:i"', " and in jquery to " format: 'dd-mm-yy - hh:ii', " and it works.

Please or to participate in this conversation.