I am trying to use the Bootstap DateTime picker in a Laravel project.
https://www.malot.fr/bootstrap-datetimepicker/
I am working on an edit page where a date is pulled from the database and should display formatted as mm/dd/yyyy hh:ii in an input field. I need that DT picker to start off from the same DT. I cannot figure out how to do it without messing up the InitialDate for the timePicker. If I add a formatted value to the input value field, it sends the InitialDate of the DT picker back to Dec 1899.
Here is the Javascript portion of the code:
<script src="{{asset('/assets/plugins/bootstrap-datetime-picker/js/bootstrap-datetimepicker.js')}}"></script>
$(".form_datetime").datetimepicker({
format: "mm/dd/yyyy hh:ii",
initialDate: "{{ $post->post_date }}",
autoclose: true,
todayBtn: true,
pickerPosition: "bottom-left",
minuteStep: 10
});
Here is the form field without the formatted DT.
<input class="form-control @error('post_date') is-invalid @enderror" type="text" value="" readonly id="post_date" name="post_date">
Here is the form field with the formatted DT:
{{ $post->post_date->format('m/d/Y H:i:s') }}
You can try this
{{ \Carbon\Carbon::parse($post->post_date)->format('m/d/Y H:i:s') }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.