How to convert timestamp from the database to populate a datetime-local field?

3

I need to fill in a field:

<input id="date" type="datetime-local" class="form-control" value="{{$task->date}}" name="date">

The return comes in timestamp format,
2016-09-20 10:00:00 ), there is some helper in> laravel to convert the format?

    
asked by anonymous 19.09.2016 / 16:26

3 answers

3

I got it, I used it this way:

<input id="date" type="datetime-local" class="form-control"
                                   value="{{date("Y-m-d\TH:i:s", strtotime($task->date))}}"
                                   name="date" placeholder="Data">
    
19.09.2016 / 16:49
1

I input type date of HTML5 only accepts a type of formatting, which is AAAA/mm/dd or 2016-09-19 , knowing this you can do as follows.

<input type="date" class="form-control" value="{{ date('Y-m-d H:i:s', strtotime($task->date)) }}">
    
19.09.2016 / 16:35
1

Just to illustrate, I think it would be something like:

<input id="date" type="datetime-local" class="form-control" value="{{Carbon::createFromFormat('Y/m/d H:i:s', $task->date)->toDateTimeString()}}" name="date">
    
19.09.2016 / 16:42