我正在尝试创建一个程序,在付款到期日通知我。我几乎知道它是如何完成的,但仍然存在一个问题。假设客户在 2017 年 1 月 31 日开设了账户。下一个到期日是 2/28/18(一个月后)。我的代码指出,如果今天的日期少于保单开启的日期,则不要将其计为一个月(因为还没有过去整整一个月),因此即使它应该算作整月也不会.
这段代码几乎适用于所有日期,除了 2 月的最后一天,或者该月在 30 日结束并且保单在 31 日开放。
$today = time();
$policy_opened = strtotime($policy_opened);
//number of months the policy has been opened
$year_opened = date('Y',$policy_opened);
$year_now = date('Y',$today);
$month_opened = date('m',$policy_opened);
$month_now = date('m',$today);
$day_opened = date('d',$policy_opened );
$day_now = date('d',$today);
$months_since_opened = (($year_now - $year_opened) * 12) + ($month_now - $month_opened);
$months_since_opened = $months_since_opened + 1; //since it can't start with 0 months opened.
if($day_now < $day_opened){
//this is in order to count it as one month only if a 'whole month' has passed by.
$months_since_opened = $months_since_opened - 1;
}