【发布时间】:2019-01-29 17:45:15
【问题描述】:
我需要根据客户表计算年龄取决于生日。
这是我的代码:
// customer age
function calculate_customer_age($startDate,$endDate){
$endDate=date(m-d-y);
$startDate= $customer['birthday'];
$fromDate= new DateTime($startDate);
$toDate= new DateTime($endDate);
echo $fromDate->diff($toDate)->days;
}
在最后一行,我需要回显年龄计算取决于从MySQL 的客户表中检索。
【问题讨论】:
-
运行代码时会发生什么?错误?结果错误?顺便说一句,您可以完全删除
$endDate变量。如果你只是做$toDate = new DateTime(),你会得到当前日期。 -
不确定是不是拼写错误,但
date(m-d-y)应该是date('m-d-y')。 -
你想通过这段代码实现什么?
标签: php