-5

我在 PHP 脚本中有 2 个变量:

$birthday = "1977-10-03";

$now = time();

如何计算生日前剩余天数($daysRemaining = ?

4

2 回答 2

0

尝试这个:

$birthday = strtotime("1977-10-03");
$now = time();
$datediff = $now - $birthday;
$daysRemaining = floor($datediff/(60*60*24));
echo $daysRemaining;
于 2013-09-04T14:32:51.883 回答
0

php中的重复日期差异在几天内?

编辑:

$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));
}
于 2013-09-04T14:33:09.163 回答