2

如何以表格返回日期的格式(Y:m:d)仅显示日期(无时间)?当我在sql中选择日期时,它会显示为图片1(例如:2012-04-10),保存并显示回来后它会显示为图片2(例如:2012年4月10日12:00:00)。我想如何在表返回日期中显示为(例如:2012-04-10)而不是显示为(例如:2012 年 4 月 10 日 12:00:00)。谢谢

图片1

在此处输入图像描述

图二

在此处输入图像描述

在 Result.php 下

$query = "SELECT ....BE.[batch_id],BED.[ReturnDate] 
FROM .... as BE 
INNER JOIN .... as BED
ON BE.[batch_exception_id] = BED.[batch_exception_id]
WHERE BE.[process_date_time] between '$date1' and '$date2'"; 

while ($row = mssql_fetch_assoc($result)) {   
$rDate = $row['ReturnDate'];
$beID = $row['batch_exception_id'];                         
$proc_dt = $row['process_date_time'];
$batchid = $row['batch_id'];
echo "<tr>";
echo "<td>" . $beID . "<input type='hidden' name='beID[$i]' value='$beID'/></td>";
echo "<td>" . $batchid . "<input type='hidden' name='batchid[$i]' value='$batchid'/></td>";
echo "<td>" . $proc_dt . "<input type='hidden' name='procDT[$i]' value='$proc_dt'/></td>";

echo "<td>";
$date="date[".$i."]"; 
echo "<input type='text' name='date[$i]' id='$date' value='$rDate' onclick=\"fPopCalendar('".$date."')\">";
$i++;
echo "</td>";
echo "</tr>";   
}

在 Save.php 下

//Select database
$selected = mssql_select_db($myDB, $link)or die("Couldn't open database $myDB");

for ($i=0; $i<$tot_rec;$i++) {
$ret_date=trim($arrretDate[$i]);
ECHO "$ret_date<br>";
if (strlen($ret_date)>0) {
$query = "UPDATE .....
SET [ReturnDate] = '$ret_date'
WHERE [batch_exception_id]= '$arrbeID[$i]'";

$result = mssql_query($query);}
}
//execute the SQL query                     
if ($result){   
header("Location:....");}
else{   
echo "Error Save";   
}
4

4 回答 4

31

你可以试试这个 date('Y:m:d', strtotime($date));

于 2012-04-19T11:04:59.173 回答
3

您可以使用:strftime("%Y-%m-%d",$date);. 另请检查链接。

文档内容:

strftime — 根据区域设置格式化本地时间/日期

说明:字符串 strftime ( string $format [, int $timestamp = time() ] )

%Y  Four digit representation for the year  Example: 2038
%m  Two digit representation of the month   01 (for January) through 12 (for December)
%d  Two-digit day of the month (with leading zeros) 01 to 31
于 2012-04-19T11:09:16.813 回答
0

尝试这个..

SELECT DATE( ReturnDate ) as dat FROM Batch

返回日期:2012年9月12日12:24:12

日期:2012 年 9 月 12 日

于 2012-04-19T11:17:46.217 回答
0

您可以使用date()函数以任何格式显示日期。

于 2012-04-19T11:06:33.743 回答