Reputation: 270
I have created a table with field date_time and its data type is datetime.
I am fetching records from this table using PHP, and I want to show this date and time in HTML page.
<input type="datetime-local" name="date"/>
I am setting its value attribute, but its not showing the date, Is there any conversion I need to perform to show this date time in input of HTML?
Upvotes: 0
Views: 2445
Reputation: 3763
You need to convert the mysql date value to the default format of datetime-local of HTML, Use this function for conversion.
date ('Y-m-d\TH:i:s', strtotime($Yordatevalue));
Upvotes: 1
Reputation: 1447
This should help:
<?php
$date = '2020-05-12T08:30'; // Or how you fetch the records?
?>
<input type="datetime-local" name="date" value="<?php echo $date;?>"/>
Upvotes: 0