2011-01-28 29 views
0

我使用wordpress作为我的平台,并且我添加了一个额外的数据库进行自定义,当我使用从数据库查询和转换数据格式时,wordpress回显错误:Warning: date() expects parameter 2 to be long, string given in D:\www\forums\wordpress\wp-content\plugins\exec-php\includes\runtime.php(42) : eval()’d code on line 249,如何解决?PHP日期格式在wordpress中的转换错误

<?php 
... 
while($result = mysql_fetch_array($resultset)) 
{ 
$date = date('Y/m/d g:i A',$result['date']);//line 249 
... 
?> 
<div class="date"><?=$date;?></date> 
... 
<?php 
} 
?> 
+0

`$ result [“date”]`包含什么? – 2011-01-28 22:34:38

回答

4
<?php 

while($result = mysql_fetch_array($resultset)) 
{ 
    $date = date('Y/m/d g:i A',strtotime($result['date']));//line 249 
... 

尝试包装你的结果日期的strtotime()

+0

Thaxs给所有人,但加上时间是一种更好的方式。 – cj333 2011-01-28 22:58:20

0

试试这个:

<?php 
... 
while($result = mysql_fetch_array($resultset)) 
{ 
if($result['date']){$date = date('Y/m/d g:i A',$result['date']);}else{$date="empty";} 
... 
?> 
<div class="date"><?=$date;?></date> 
... 
<?php 
} 
?> 

也许它只是有时候空!

0

理想情况下,你将能够修改查询并返回一个UNIX_TIMESTAMP ..

SELECT UNIX_TIMESTAMP(date) AS `timestamp` ... 

,那么你就能时间戳传递给date()函数正常。