I would like to set the value of an input:datetime-local field in Blade with data from the database but it only shows a blank placeholder values.
Below is my attempt which is not working:
<input type="datetime-local" value="{{ date('d/m/YH:i', strtotime($slider->run_to)) }}">
In my research, I have found out that the field needs value in this format YYYY-MM-DDTHH:MM or like in my case d/m/YTH:i where T is a string literal.
My problem is I am not able to find a way to do this in Laravel-Blade with dynamic data.
Is there any way to achieve it? If not then what alternatives are there for displaying date time in an input field?
The format of datetime-local value format isn't similar to what we see on the browser by default.
I'll replace your
$slider->run_towith the validdatetime'2022-03-17 23:59:26'to provide my solutioncthat stands for ISO 8601 date which outputs'2022-03-17T23:59:26+01:00'.':26+01:00'substr$lengthof19wouldn't break the element.Demo: https://3v4l.org/aMpMN
Another alternative solution that includes seconds:
Demo: https://3v4l.org/710EN