开发者

PHP date format conversion fault in wordpress

开发者 https://www.devze.com 2023-02-07 14:39 出处:网络
I use wordpress开发者_如何转开发 as my platform, and I add a additional database for customize, when I use a query from that database and conversion a data format, the wordpress echo fault: Warning: d

I use wordpress开发者_如何转开发 as my platform, and I add a additional database for customize, when I use a query from that database and conversion a data format, the wordpress echo fault: 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, how to solve?

<?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
}
?>


<?php

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

Try wrapping your result date in strtotime()


try this:

<?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
}
?>

maybe its just sometimes null!


Ideally, you will be able to modify the query to return a UNIX_TIMESTAMP..

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

then you will be able to pass the timestamp to the date() function normally.

0

精彩评论

暂无评论...
验证码 换一张
取 消