在php循环中跳过日、月和周之间的周末
我要求用户输入开始日期和结束日期以生成付款计划,我在这两个日期内循环以根据用户选择生成每周、每天和每月的计划在php循环中跳过日、月和周之间的周末,php,Php,我要求用户输入开始日期和结束日期以生成付款计划,我在这两个日期内循环以根据用户选择生成每周、每天和每月的计划 $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 mo
$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);
$f\u还款日期=“2015-01-01”;
$mat_date=“2015-10-01”;
while(strotime($f_还款日期)0);
您可以使用日期
功能:
$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';
你被困在哪里了,你尝试了什么?你会犯什么错误?你想达到什么目的?请用这些信息更新你的帖子。也许还可以添加一个例子。@TeeDeJee想跳过两个日期之间的周末。谢谢你试过谷歌吗?这个问题已经有很多答案了。请问我应该把循环放在哪里?