在HTML表中显示日期
问题描述:
我正在查询SQL Server并从查询中创建结果集表。我的表中的前两个字段显示为他们应该,但日期字段总是留空,这让我看到这个领域是我的问题。下面是问题语法 - 我应该如何改变它,以便它实际上在表中显示我的日期字段?在HTML表中显示日期
$query->select($db->quotename(array('UnitID,SaleAmt,SaleDate')));
$query->from($db->quoteName('SaleInformation'));
$datefield_name = $db->quoteName('SaleDate');
$query->where("$datefield_name >= " . $db->quote($startdate), 'AND');
$query->where("$datefield_name <= " . $db->quote($enddate));
} else {
echo "Please check the selection criteria and process again.";
}
$db->setQuery($query);
$query = $db->loadObjectList();
?>
<div id="dvdata">
<table id="example" border="1" >
<thead>
<tr>
<th>Job Number </th>
<th>SaleAmt </th>
<th>Sale Date</th>
</tr>
</thead>
<?php
foreach ($query as $res) {
print "<tr>";
print "<td><a href='http://internallocalhost/test" . $res-> . "' target=_blank>" . $res->UnitID . "</a></td>";
print "<td>" . "$" . number_format(round($res->SaleAmt)) . "</td>";
print "<td>" . date('d-m-Y', strtotime($res['SaleDate'])) . "</td>";
print "</tr>";
}
}
?>
答
我觉得你只是把错误object
为array
$查询= $ DB-> loadObjectList();加载结果作为stdClass的对象列表对象 所以试试这样。
print "<td>" . date('d-m-Y', strtotime($res->SaleDate)) . "</td>";
我也有一个关于语法$水库 - >就行了疑问,
print "<td><a href='http://internallocalhost/test" . $res-> . "' target=_blank>" . $res->UnitID . "</a></td>";
我认为SaleDate不是一个字符串,但日期时间,所以基于这样的观察尝试的日期函数即date('m/d',$ res ['SaleDate']) – Namphibian