我在PHP脚本中有两个变量:
$birthday = "1977-10-03";
$now = time();
如何计算生日前的剩余天数($daysRemaining = ?
)
答案 0 :(得分:0)
试试这个:
$birthday = strtotime("1977-10-03");
$now = time();
$datediff = $now - $birthday;
$daysRemaining = floor($datediff/(60*60*24));
echo $daysRemaining;
答案 1 :(得分:0)
重复Date Difference in php on days?
<强>编辑:强>
$diff=$date-time();//time returns current time in seconds
$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day)
$hours=round(($diff-$days*60*60*24)/(60*60));
这是你想要的吗?
$birthday = "1977-9-10";
$cur_day = date('Y-m-d');
$cur_time_arr = explode('-',$cur_day);
$birthday_arr = explode('-',$birthday);
$cur_year_b_day = $cur_time_arr[0]."-".$birthday_arr[1]."-".$birthday_arr[2];
if(strtotime($cur_year_b_day) < time())
{
echo "Birthday already passed this year";
}
else
{
$diff=strtotime($cur_year_b_day)-time();//time returns current time in seconds
echo $days=floor($diff/(60*60*24));
}