我想计算expiry date
百分比。但我的starting date
和expirydate
格式为m/d/Y
。我如何找到starting date
之间的天数和ending date
???这是我的代码......
foreach ($result['query'] as $row) {
$validitystart = $row->validitystart;
$expirydate = $row->expirydate;
$today = date('m/d/Y');
$maxdiff = date_diff($expirydate, $validitystart);
$diff = date_diff($expirydate, $today);
$percentage = ($diff * 100) / $maxdiff;
}
答案 0 :(得分:3)
在StackOverflow上的数百个重复项中,您可能已经找到了类似的东西并进行了一些搜索
$date1 = DateTime::createFromFormat('m/d/Y', $date1);
$date2 = DateTime::createFromFormat('m/d/Y', $date2);
$diffDays = $date2->diff($date1)->format("%a");