gpt4 book ai didi

php - 如何循环基于每月或每周的贷款摊销日期范围

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:09 26 4
gpt4 key购买 nike

我正在制定贷款分期偿还计划,需要日期循环的帮助。我已经能够获得付款时间表,但需要有关包含日期的帮助。请帮我处理日期循环。谢谢

echo '<table border="1">';
echo '<tr><th>#</th><th>PAYMENT</th><th>INTEREST</th><th>PRINCIPAL</th><th>BALANCE</th></tr>';
$start_date = '2014-12-14';
$end_date = '2015-03-12';
$count = 0;
do {
$count++;

// calculate interest on outstanding balance
$interest = $balance * $rate/100;

// what portion of payment applies to principal?
$principal = $payment - $interest;

// watch out for balance < payment
if ($balance < $payment) {
$principal = $balance;
$payment = $interest + $principal;
} // if

// reduce balance by principal paid
$balance = $balance - $principal;

// watch for rounding error that leaves a tiny balance
if ($balance < 0) {
$principal = $principal + $balance;
$interest = $interest - $balance;
$balance = 0;
} // if

echo "<tr>";
echo "<td>$count</td>";
echo "<td>" .number_format($payment, 2, ".", ",") ."</td>";
echo "<td>" .number_format($interest, 2, ".", ",") ."</td>";
echo "<td>" .number_format($principal, 2, ".", ",") ."</td>";
echo "<td>" .number_format($balance, 2, ".", ",") ."</td>";
echo "</tr>";

@$totPayment = $totPayment + $payment;
@$totInterest = $totInterest + $interest;
@$totPrincipal = $totPrincipal + $principal;

if ($payment < $interest) {
echo "</table>";
echo "<p>Payment < Interest amount - rate is too high, or payment is too low</p>";
exit;
} // if

} while ($balance > 0);

echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td><b>" .number_format($totPayment, 2, ".", ",") ."</b></td>";
echo "<td><b>" .number_format($totInterest, 2, ".", ",") ."</b></td>";
echo "<td><b>" .number_format($totPrincipal, 2, ".", ",") ."</b></td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "</table>";

谢谢

最佳答案

$timestampInOneWeek = strtotime('+1 week');
$timestampOneMonthAfter01january = strtotime('+1 month', 1419984000);

您还可以使用 DateTime::add

$month_later = new DateTime('2000-01-01');
$month_later->add(new DateInterval('P1M'));

关于php - 如何循环基于每月或每周的贷款摊销日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30439573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com