将php datetime转换为sql中的字符串结果

时间:2018-02-27 16:03:46

标签: php sql-server

程序在php页面的表格中显示sql表。

查询,包含25列:

$stmt = "SELECT * FROM table";
$query = sqlsrv_query($conn, $stmt);

将它放在一张桌子上25次,直到它到达日期:

   <?php echo $result["Date"]  ;?>

表格中显示错误:

Recoverable fatal error: Object of class DateTime could not be converted to string in filepath/table.php on line 73

如何将datetime转换为字符串?

1 个答案:

答案 0 :(得分:0)

如果$result["Date"]是\ DateTime的实例,则必须使用format()方法。

echo $result["Date"]->format('Y-m-d');