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).