我要求用户输入开始日期和结束日期以生成付款时间表,我会在两个日期内循环,根据用户选择生成每周,每日和每月的时间表。
$f_repayment_date = "2015-01-01";
$mat_date = "2015-10-01";
while (strtotime($f_repayment_date) < strtotime($mat_date)) {
$f_repayment_date = date ("Y-m-d", strtotime("+1 month", strtotime($f_repayment_date)));
$count++;
//calculate interest on outstanding balance
if ($balance < $payment) {
$payment = $balance;
$interest_amount = $interest_amount ;
$principal = $payment - $interest_amount;
$due = $payment + $interest_amount;
}
$balance = $balance - $payment;
if ($balance < 0) {
$principal = $principal + $balance;
$interest_amount = $interest_amount;
$balance = 0;
}
$sql = mysql_query("insert into loan_schedule values (NULL,'$f_repayment_date','$account_number','$contract_code','$loan_product',
'$loan_amount','$frequency','$loan_term','$interest','$payment','$principal','$interest_amount','$balance','$due','$count','','$due','$active_loan')");
}
} while ($balance > 0);
答案 0 :(得分:1)
您可以使用date
功能:
$weekends = array(6, 7);
$day = date('N', strtotime('2015-10-01'));
if (in_array($day, $weekends)) {
continue; // skip this day
}
您还应该将日期用引号括起来,否则您将获得2013
而不是'2015-01-01'
:
$f_repayment_date = '2015-01-01';
$mat_date = '2015-10-01';