Calculating a value proportional to the date of the month

1

I'm putting together a script in php that will run on the 1st day of each month, generating an account to receive based on a value of 120,00 . That is, on the first day of each month it creates a 120.00 account.

The problem is that if the customer starts using the service on the 15th or any other day, he has to pay a value proportional to the days that he used. This is simple, I divide the 120.00 by the days of the month and then multiply by the days used. The problem is that I have no idea how to recover the days used.

If anyone can help me.

Follow the variables with the data I retrieve from DB.

$valor_mensalidade = 120;
$data_inicio = "2016-06-15";
    
asked by anonymous 09.06.2016 / 15:31

1 answer

2

Live,

What I thought was: to know how many days had this month .. divide the value by the days of the month .. then multiply the result for the past months ..

$valueMonth = 120;
$dateInit = '2016-06-15';
$totalDays = date('t', strtotime($dateInit));
$used = date('d', strtotime($dateInit));
$result = ($valueMonth/$totalDays)*$used;

I think that's what you want, if you do not tell;)

Embrace

    
09.06.2016 / 15:44