[英]Comparing current date to a repeating day of the month
如何将当前日期(以任何格式)与每月的静态重复日期进行比较。
比如我有due date
的5
这是当我的租金是因为,我要天天比较当前日期,以便在5th
每月然后我就可以知道有多少天,直到5th
或自5th
有没有一种方法可以在不将我的due date
设置为timestamp
或类似的due date
情况下,然后在达到该due date
进行更新?
您可以执行以下操作:
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.');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.