我已经创建了一个函数来生成一周前,今天和一周后的生日成员列表。该功能是PHP日期比较找到时间戳1970年之前的生日?
$m= date("m"); // Month value
$de= date("d"); //today's date
$y= date("Y"); // Year value
for($i=0;$i
$m_bday = strtotime($members[$i]->dob);
$bday_date = date('d',$m_bday);
$bday_month = date('m',$m_bday);
$bday = strtotime(date('Y-m-d',mktime(0,0,0,$bday_month,$bday_date,$y)));
//echo $bday_date."".$bday_month."".$members[$i]->dob."".date('Y-m-d',$bday);exit;
$week_before = strtotime(date('Y-m-d', mktime(0,0,0,$m,($de-7),$y)));
$week_after = strtotime(date('Y-m-d', mktime(0,0,0,$m,($de+7),$y)));
if(date('d-m') == date('d-m',$bday)){
$this->present_bday[] = array('mem_name'=> $members[$i]->name);
}
else if(date('d-m',$week_before) <= date('d-m',$bday) && date('d-m',$bday) < date('d-m')){
$this->past_bday[] = array('mem_name' => $members[$i]->name);
}
else if(date('d-m')< date('d-m',$bday) && date('d-m',$bday) <= date('d-m',$week_after)){
$this->future_bday[] = array('mem_name' => $members[$i]->name);
}
}
从数据库返回的日期格式为yyyy-mm-dd即1960-06-12。此代码在1周之前和今天工作正常,但返回后1周内,如果年份低于1970年,并且条件完全失败后1周。
任何人都可以为我提供正确的日期操作以获得正确的结果吗?