我在我的数据库中有两个用户,其出生日期被设定为:PHP:奇怪的日期问题
1985-01-26
后来才知道有哪些时提供的用户的最新功能,告诉多少天都留在了生日。下面是函数:
function retage($iy,$im,$id)
{
if(!empty($iy)>0 && intval($im)>0 && intval($id)>0)
{
$tdo=$iy.'-'.$im.'-'.$id;
$tdc=date('Y').'-'.$im.'-'.$id;
/*echo "<br/>";*/
$cd=date('Y-n-j');
/*echo "<br/>";*/
if(strtotime($tdc)>strtotime($cd))//coming
{
$ty=floor((strtotime($tdc)-strtotime($tdo))/(3600*24*365));
$td=floor((strtotime($tdc)-strtotime($cd))/(24*3600));
if($td==1)
{
$td=round((strtotime($tdc)-strtotime($cd))/(24*3600)).' day to go';
}
else
{
$td=round((strtotime($tdc)-strtotime($cd))/(24*3600)).' days to go';
}
$ty='<font color="#C7C5C5">is turning '.$ty.' on <br>'.date('M jS Y',strtotime($tdc)).'</font>';
//return 'is turning '.$ty.' on '.$tdc;
}
elseif(strtotime($tdc)<strtotime($cd))//past
{
$ty=floor((strtotime($tdc)-strtotime($tdo))/(3600*24*365));
if($ty>0)
{
//$td='gone '.floor((strtotime($cd)-strtotime($tdc))/(24*3600)).' days ago';
$ndays=floor((strtotime($cd)-strtotime($tdc))/(24*3600));
if($ndays==1)
$td=' gone '.round((strtotime($cd)-strtotime($tdc))/(24*3600)).' day ago';
else
$td=' gone '.round((strtotime($cd)-strtotime($tdc))/(24*3600)).' days ago';
$ty='<font color="#C7C5C5">had turned '.$ty.' on <br>'.date('M jS Y',strtotime($tdc)).'</font>';
//return 'had turned '.$ty.' on '.$tdc;
}
else
{
$tdc=(date('Y')+1).'-'.$im.'-'.$id;
$ty=floor((strtotime($tdc)-strtotime($tdo))/(3600*24*365));
//$td=floor((strtotime($tdc)-strtotime($cd))/(24*3600)).' days to go';
$td=floor((strtotime($tdc)-strtotime($cd))/(24*3600));
if($td==1)
{
$td=round((strtotime($tdc)-strtotime($cd))/(24*3600)).' day to go';
}
else
{
$td=round((strtotime($tdc)-strtotime($cd))/(24*3600)).' days to go';
}
$ty='<font color="#C7C5C5">is turning '.$ty.' on <br>'.date('M jS Y',strtotime($tdc)).'</font>';
//return 'is turning '.$ty.' on '.$tdc;
}
}
else//today
{
$ty=floor((strtotime($tdc)-strtotime($tdo))/(3600*24*365));
if($ty>0)
{
$td='today';
$ty='<font color="#C7C5C5">has turned <br>'.$ty.' on today </font>';
//return 'has turned '.$ty.' on today';
}
else
{
$ty='<font color="#C7C5C5">today</font>';$td='';
//return '';
}
}
}
else
{
$ty='';$td='';
//return '';
}
$ta[0]=$ty;
$ta[1]=$td ;
return $ta;
}
我用下面的代码来显示剩余天数:
while($rs=mysql_fetch_array($result))
{
if (isset($rs['byear'],$rs['bmonth'],$rs['bdate']))
{
$tmptxt = retage($rs['byear'],$rs['bmonth'],$rs['bdate']);
echo $tmptxt[1];
}
}
奇怪的是,对于一个用户来说,剩余天数显示正确例如:
gone 120 days ago
对于具有相同出生日期的其他用户,显示如下:
Jan 1st 1970 -14755 days to go
奇怪:
当我使用相同功能的回路和测试的外侧日期1985-01-26
,正确的结果被示出。
注意:您可以自己查看该功能。
您能否告诉我可能有什么错误,您的帮助将得到高度赞赏。
谢谢。
FFS,使用变量名称实际上意味着什么。难怪你被卡住了。 – 2010-05-26 13:20:25