繁体   English   中英

用Php和SQL Server将日期时间转换为字符串时出现问题

[英]Problem when converting a date time to string with Php and SQL Server

我在执行数据时将数据类型日期从SQL Server获取到Php时遇到问题,出现以下消息。

可捕获的致命错误: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>

如果我删除该数据,则问题是由key1 [2]生成的。

您应该使用DateTime :: format()

$key1[2]->format('dd/mm/YYYY');

文档: http : //php.net/manual/en/datetime.format.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM