[英]Problem when converting a date time to string with Php and SQL Server
I have a problem getting a data type date from SQL Server to Php at the moment of executing it, below message appears. 我在执行数据时将数据类型日期从SQL Server获取到Php时遇到问题,出现以下消息。
Catchable fatal error: Object of class DateTime could not be converted to string in 可捕获的致命错误:DateTime类的对象无法在以下位置转换为字符串
$sql1="select id,name,date";
$output1= array(
array( 'none' )
);
executeSQL($sql1, $output1);
?>
<table>
<thead>
<th>id</th>
<th>name</th>
<th>date</th>
</thead>
<tbody id="fbody">
<?php
foreach($output1 as $key1){
?>
<td><?=$key1[0];?></td>
<td><?=$key1[1];?></td>
<td><?=$key1[2];?></td>
<?php
}
?>
</tbody>
</table>
The problem is generated by key1[2] if I remove that data if it works. 如果我删除该数据,则问题是由key1 [2]生成的。
You should use DateTime::format() 您应该使用DateTime :: format()
$key1[2]->format('dd/mm/YYYY');
Documentation: http://php.net/manual/en/datetime.format.php 文档: http : //php.net/manual/en/datetime.format.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.