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

dmcglone27's avatar

Getting date from db in different format

I'm using the bootstrap datepicker, to insert a date into the db, but in order to use carbon, so I convert the date before inserting it into the db using

        $input['date'] = Carbon::createFromFormat('m/d/Y', $request->date)->format('Y-m-d');

My problem is when I go to the edit page, my date field cannot be populated, because the date is a carbon instance, so I'm trying to convert it back to m/d/Y format for editing. here's my form

                {!! Form::text('date', $meetings->date, array('class' => 'form-control', 'input-group date', 'id' => 'datetimepicker', 'required' => 'required')) !!}

I've tried using several ideas

 $meetings->date->format('Y-m-d')
 format('Y-m-d', $meetings->date)

And several other ways.

So how can I get the date in the correct format to populate the field?

0 likes
6 replies
cviv's avatar

I didn't have any problem with my datetimepicker. I just added this script

<script type="text/javascript">
            $(function () {
                $('#datetimpicker').datetimepicker({
                    format: 'YYYY-MM-DD',
                    useCurrent: true
                });
            });
        </script>

it formats my datetimepicker

1 like
dmcglone27's avatar

Ah Thank you! Worked perfectly. I couldn't find these timepicker options on the web.

Thanks @cviv

dmcglone27's avatar

@mstnorris Yeah I tried that, and then my view would complain it couldn't find ->diffForHumans() etc etc..

But then again I've been at this for about a day, so everything was just jumbled up. But the options @cviv suggested worked perfectly. :-)

1 like

Please or to participate in this conversation.