【发布时间】:2010-11-09 21:57:46
【问题描述】:
我正在寻找一个从日期开始计算年份的函数,格式为:0000-00-00。 找到了这个功能,但是不行。
// Calculate the age from a given birth date
// Example: GetAge("1986-06-18");
function getAge($Birthdate)
{
// Explode the date into meaningful variables
list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $Birthdate);
// Find the differences
$YearDiff = date("Y") - $BirthYear;
$MonthDiff = date("m") - $BirthMonth;
$DayDiff = date("d") - $BirthDay;
// If the birthday has not occured this year
if ($DayDiff < 0 || $MonthDiff < 0)
$YearDiff--;
}
echo getAge('1990-04-04');
什么都不输出:/
我有错误报告,但我没有收到任何错误
【问题讨论】:
-
这个函数没有
return行,因此它不输出任何东西。看起来很不完整。