如何将当前日期,任何格式与当月的静态重复日进行比较。
例如,我有due date
5
,这是我的租金到期时间,我想每天比较当前日期,以便在每个月的5th
我可以知道到5th
或5th
有没有办法在不将我的due date
设置为timestamp
或类似的情况下执行此操作,然后在到达时更新?
答案 0 :(得分:0)
你可以这样做:
function date_diff_in_days($date1, $date2) {
$date1 = strtotime($date1);
$date2 = strtotime($date2);
$diff = $date2 - $date1;
return floor($diff/86400); // 86400 is one day in seconds
}
// compare the due date to the current date
$days = date_diff_in_days($due_date, time());
$past_due = $days < 0;
$days = abs($days);
// show your result
echo 'Your bill is '.($past_due
? 'past due by '.$days.' days.'
: 'due in '.$days.' days.');