2012-04-19 57 views
-1

如何仅使用格式(Y:m:d)为表格返回日期显示日期(无时间)?当我在sql中选择日期时,它会以picture1的形式显示(例如:2012-04-10),保存并显示后,它会查看为图片2(例如:Apr 10 2012 12:00:00)。我想如何在表格返回日期显示为(例如:2012-04-10)不显示为(例如:Apr 10 2012 12:00:00)。感谢如何仅在PHP中显示日期?

图片1

enter image description here

图片2

enter image description here

下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"; 
} 
+0

看一看这里http://php.net/manual/en/class.datetime。 php – wgcrouch 2012-04-19 11:03:25

+0

你想要做什么?什么是输入日期格式,你想得到什么? – 2012-04-19 11:06:07

+0

只是编辑的问题,并做了不好的解释道歉 – srahifah 2012-04-20 01:43:49

回答

19

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

+0

嗨,盖伊,我得到这个错误,当使用strtodate:调用未定义的函数strtodate() – srahifah 2012-04-20 01:56:58

+1

我的错误是strtotime;) – gmaliar 2012-04-25 06:24:04

0

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

2

您可以使用:strftime("%Y-%m-%d",$date);。同时检查this链接。从文档

内容:

的strftime - 根据区域设置

描述格式的本地时间/日期:串的strftime(字符串$格式[摘要$时间戳=时间( )])

%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 
0

试试这个..

SELECT DATE(ReturnDate) as dat FROM Batch 

返程日期:2012年9月12日12点24分12秒

DAT:2012年9月12日

+0

嗨Jey,我不能使用上面,因为在SQL 2005没有日期..只有日期时间只有 – srahifah 2012-04-20 01:59:55

+0

选择日( ReturnDate)作为来自批量的数据或选择DATEPART(datepart,ReturnDate)作为来自批量的数据 – Vaishu 2012-04-20 04:38:40