How to show date-time in laravel field?

808 Views Asked by At

Technology - Laravel8 How can I show value date-time in field?

I tried to do this in this way, but it wasn't successfull.

{!! Form::input('datetime-local', 'startdatetime', $auction->startdatetime, array('class' => 'form-control')) !!}

Example on value of ($auction->startdatetime) => "2021-01-24 08:00:00"

2

There are 2 best solutions below

0
On

I solved it like this.

In controller class..

`$starttime = strtotime($auction->startdatetime);

$auction->startdatetimeformat = date('Y-m-d', $starttime)."T".date('H:i', $starttime);`

In view file..

{!! Form::input('datetime-local', 'startdatetime', $auction->startdatetimeformat, array('class' => 'form-control')) !!}

0
On

Try this:

date('d-m-Y', strtotime($auction->startdatetime));

It will convert the date into d-m-Y or whatever format you have given.

Note: This solution is a general solution that works for PHP and any of its frameworks. For a Laravel specific method.

Thanks :)