生日前的最后一天

时间:2012-10-31 15:52:44

标签: php zend-framework

我在生日前的最后一天搜索一个函数来计算。

2 个答案:

答案 0 :(得分:1)

$timestamp = strtotime("yesterday", $birthday);

$ birthday必须是时间戳,如果$ birthday是一个像“1992-09-98”的字符串,你必须像这样改变它

$birthday = strtotime($birthday);

答案 1 :(得分:0)

function daysLeftForBirthday($devabirthdate)
{
    /* input birthday date format -> Y-m-d */
    list($y, $m, $d) = explode('-',$devabirthdate);
    $nowdate = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
    $nextbirthday = mktime(0,0,0,$m, $d, date("Y"));

    if ($nextbirthday<$nowdate)
        $nextbirthday=$nextbirthday+(60*60*24*365);

    $daycount=intval(($nextbirthday-$nowdate)/(60*60*24));

    return $daycount;
}