function nextBillDate($firstBillDate) {
$firstBillDateVal = strtotime($firstBillDate);
$todayVal = strtotime(date('Y-m-d', strtotime("+8 hours")));
if ( $todayVal < $firstBillDateVal) {
$nextBillDateVal = $firstBillDateVal; // first bill date in future
} elseif ($todayVal == $firstBillDateVal) {
$nextBillDateVal = strtotime('+1 month -1 day', $firstBillDateVal); // today is first bill date
} elseif ($todayVal > $firstBillDateVal) {
$this_year_date = sprintf("%s-%s", date('Y-m', strtotime("+8 hours")), date('d', $firstBillDateVal));
$pay_date = date('Y-m-d', date(strtotime('-1 day', strtotime($this_year_date))));
$nextBillDateVal = strtotime($pay_date);
if ($nextBillDateVal < $todayVal) {
$nextBillDateVal = strtotime("+1 month", $nextBillDateVal);
}
$nextBillDateVal = $nextBillDateVal;
}
return(date('Y-m-d', $nextBillDateVal));
}
printf("Next Bill Date: %s", nextBillDate("2019-02-29"'));
Post Views: 1