Laravel – Display DateTime Value in Edit Form

How can I display my data which is a DateTime value in my edit form?

input="datetime-local."

Here’s what my DateTime value looks like: 2018-04-02 04:04:00.

I want it to display in this input:

<input type="datetime-local" name="flight_date" class="form-control">

my $variable->data
$aircraftFlight->flight_date

EDIT VAR DUMP

object(AppAircraftFlights)#527 (26) { [“table”:protected]=>
string(16) “aircraft_flights” [“primaryKey”]=> string(2) “id”
[“timestamps”]=> bool(false) [“connection”:protected]=> string(5)
“mysql” [“keyType”:protected]=> string(3) “int” [“incrementing”]=>
bool(true) [“with”:protected]=> array(0) { } [“withCount”:protected]=>
array(0) { } [“perPage”:protected]=> int(15) [“exists”]=> bool(true)
[“wasRecentlyCreated”]=> bool(false) [“attributes”:protected]=>
array(9) { [“id”]=> int(1) [“flight_number”]=> string(10) “AA-0000003”
[“iata_flight_number”]=> string(5) “ABCD2” [“flight_date”]=>
string(19) “2018-04-02 04:04:00” [“departure_time”]=> string(19)
“2018-05-04 01:59:00” [“arrival_time”]=> string(19) “2018-05-05
13:59:00” [“from_location”]=> string(11) “Afghanistan”
[“destination”]=> string(7) “Albania” [“aircraft_id”]=> int(1) }
[“original”:protected]=> array(9) { [“id”]=> int(1)
[“flight_number”]=> string(10) “AA-0000003” [“iata_flight_number”]=>
string(5) “ABCD2” [“flight_date”]=> string(19) “2018-04-02 04:04:00”
[“departure_time”]=> string(19) “2018-05-04 01:59:00”
[“arrival_time”]=> string(19) “2018-05-05 13:59:00”
[“from_location”]=> string(11) “Afghanistan” [“destination”]=>
string(7) “Albania” [“aircraft_id”]=> int(1) } [“changes”:protected]=>
array(0) { } [“casts”:protected]=> array(0) { } [“dates”:protected]=>
array(0) { } [“dateFormat”:protected]=> NULL [“appends”:protected]=>
array(0) { } [“dispatchesEvents”:protected]=> array(0) { }
[“observables”:protected]=> array(0) { } [“relations”:protected]=>
array(0) { } [“touches”:protected]=> array(0) { }
[“hidden”:protected]=> array(0) { } [“visible”:protected]=> array(0) {
} [“fillable”:protected]=> array(0) { } [“guarded”:protected]=>
array(1) { [0]=> string(1) “*” } }

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I would use a date time picker with the input type as text and set the id to flight_date

have a look at this one:

https://eonasdan.github.io/bootstrap-datetimepicker/

There are a number around this is just the first I came across

Hope this helps

Update

This is the one that we use at work and I know it works

https://www.eyecon.ro/bootstrap-datepicker/

Try that.

Method 2

try using carbon to format date:

<input type="datetime-local" name="flight_date" class="form-control" value="{{ CarbonCarbon::parse($aircraftFlight->flight_date)->format('yyyy-MM-ddThh:mm')}}">

Note: type=”datetime-local” is not supported in Firefox, Safari or Internet Explorer 12 (or earlier).

Method 3

Put your variable on input type text value

<input type="text" name="flight_date" class="form-control" value="{{ $aircraftFlight->flight_date }}">

You can use php date() function to format your variable here is the link: http://php.net/manual/en/function.date.php

format into this

date('Y-m-d h:i:s', strtotime($aircraftFlight->flight_date))


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x