从php将数据获取到本地日期时间


get the data to datetime-local from php

我在数据库中有一个数据类型"TIMESTAMP"。我使用html中的"datetimelocal"属性来传递值。

<input type="datetime-local" id="start_time" class="form-control" name="start_time"/>

这很好,我可以上传日期和时间到数据库。但是,当我检索数据表单数据库进行编辑时,它不起作用。

PHP代码

$query="SELECT * FROM hire WHERE hire_id='$id'";
$query_run=mysqli_query($con,$query);
$row=mysqli_fetch_array($query_run);

HTML代码

<input type="datetime-local" value="<?php echo $row['start_time']; ?>" />

html中的上述php没有显示任何结果。这是怎么回事?

因为您将输入类型设置为"datetime local"。您必须将日期设置为正确的格式才能在输入中显示。

将start_time值更改为此格式。

$date = date("Y-m-d'TH:i:s", strtotime($row['start_time']));

然后在您的输入字段中回显$date

<input type="datetime-local" value="<?php echo $date; ?>" />

首先,如果您应该从mysql中获取日期,然后使用strtotime函数将该字符串转换为日期,然后更改日期的格式,并将其设置为input form control haivng type="datetime-local"value属性。

$string_to_date=$d=strtotime($date_fromdatabase);
$new_date=Date('Y-m-d'TH:i',$string_to_date);

设置为laravel 6 中输入元素的值属性

<input type="datetime-local"  class="form-control" value="{{ $new_date }}">