如何使用PHP基于日期划分数字?

时间:2017-01-17 15:55:48

标签: php

我有两个名为

的变量

$monthly_bill = 1200

2016-09-18 480 // Joined 18th and month end 30th = 12 days * (1200 / 30) 2016-10-01 1200 2016-11-01 1200 2016-12-01 1200 2017-01-01 1200

现在我想用月结单显示从加入日期到今天日期的所有月份。例如,循环应显示以下结果:

interact('#draggable').draggable({
    inertia: true,
    onmove: function() {},
    onend: function() {}
});

如何使用php循环显示这个?

1 个答案:

答案 0 :(得分:0)

    //cal_days_in_month : Return the number of days in a month for a given year and calendar  

----------

<?php
$join_date="2016-09-18";
$begin = new DateTime($join_date); // value is : 2016-09-18
$monthly_bill = 1200;
$date=$begin->format('d');
$month=$begin->format('m');
$year=$begin->format("Y");
$ndays=cal_days_in_month(CAL_GREGORIAN,$month,$year);
if($date>1)
{
    $totaldays=$ndays-$date;
}
else{
    $totaldays=$ndays;
}
$paidbill=$totaldays * ($monthly_bill / $ndays);
echo $paidbill."<br/>";


?>