Can't Get Bootstrap DateTime Picker To Show Formatted database Value in Form Field

173 Views Asked by At

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') }}

enter image description here

1

There are 1 best solutions below

2
khokon ahmed On

You can try this

{{ \Carbon\Carbon::parse($post->post_date)->format('m/d/Y H:i:s') }}