PHP Help

Looking for help in creating a script that will split revenue across days and output the total revenue by month (which will vary as startdate could be in middle of month).


Startdate: 08/12/2010
Enddate: 10/31/2010
Total Revenue: 10000

The script needs to determine total number of days: 80 (19 in aug, 30 in sept, 31 in oct)

determine revenue per day = take the total revenue and divide it by numdays 10000/80=125

based on the startdate and end date determine how much revenue should be applied to each month and report monthly total.

Results should be:
Aug - 2375
Sept - 3750
Oct - 3875

I wrote a scripe but im getting confused on the looping etc…

Maybe not most effective solutions for thsi task, but is quick and relatively simple:

function revenue_by_month($startdate,$enddate,$revenue){
$d1 = strtotime($startdate);
$d2 = strtotime($enddate);

$m_days = array();
$total_days = 0;
  $m = date('M-Y',$d);

$rev_day = 0;
if($total_days>0) $rev_day = $revenue/$total_days;

$res = array();
if(count($m_days)) foreach($m_days as $m=>$n_days){
  $res[$m] = $rev_day*$n_days;

return $res;

// usage example:
echo ‘

echo ‘
Sponsor our Newsletter | Privacy Policy | Terms of Service