Calculating a value proportional to the date of the month

Asked

Viewed 73 times

1

Guys I’m putting together a script on php which will be executed on the first day of each month, generating a receivable based on a value of 120.00. That is to say on the first day of each month he creates an account of 120.00.

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

If anyone can help me.

Follow the variables with the data I recover from BD.

$valor_mensalidade = 120;
$data_inicio = "2016-06-15";

1 answer

2


Long live,

What I thought was: to know how many days I had this month. to divide the value by the days of the month...

$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 don’t warn ;)

Hug

  • Well, it didn’t work out so well. See well put the following value ($dateInit = '2016-06-01';) being that today is days 09 correct, so the value in $result had to be 36,00.

  • This is 36.. http://pastebin.com/R3UwWaEM

  • for me this returning 4. $valueMonth = 120; $dateInit = '2016-06-01'; $totalDays = date(’t', strtotime($dateInit)); $used = date(’d, strtotime($dateInit)); $result = ($valueMonth/$totalDays)*$used;&#Xa result; echo $ $result;

  • If the date init is 01, you do not need to do accounts :) The date init is the date of user registration..

  • I made confusion hahahah, it worked here thank you very much

  • how would I have a variable and start and end? ie for it to calculate in a date danger?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.