1

I have 2 variables called

$joined_date = 2016-09-18 and

$monthly_bill = 1200

Now I want to show all months from joined date to today date with monthly bill. For example, the loop should show the bellow result :

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 

How can show this using php loop ?

shibbir ahmed
  • 1,014
  • 2
  • 18
  • 34

1 Answers1

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/>";


?>
Devi Veeramalla
  • 406
  • 3
  • 7