How to make an increase to an amount after the payment date has expired?

1

Greetings guys, I pose my problem:

I must make an increase of 15% to an amount after 5 days of the date on which the person had to pay. A practical example is:

Current Date: 08-30-2017 Payment Date: 08-25-2017 Total = amount + (amount * 0.15)

As you can see, that is what must be fulfilled in my conditionals.

I tried this:

$hoy = date('d-m-Y');
$fecha_pago = new DateTime($row['fecha_a_pagar']);
$fecha = new DateTime($hoy);
$diff = $fecha->diff($fecha_pago);

$multa = 0;
if($diff->days >= 5 && $diff->invert):
$multa = $row['monto']*0.15;
$total = $row['monto']+$multa;
endif;

Makes the increase well, but when I'm going to pay an advanced fee eg:

Date today: 08-30-2017
Date of quota to pay: 12-09-10

I still do the increase, I'm not comparing the months. Only the days.

    
asked by Alejo Mendoza 30.08.2017 в 17:59
source

2 answers

1

what you can do is use the diff method that gives you the difference between two dates. In this case, you could do:

<?php
        $d1=new DateTime("2017-12-25"); //$row['fecha_a_pagar']
        $d2=new DateTime(); //fecha actual
        $diff=$d2->diff($d1); 
        if($diff->days >= 5 && $diff->invert){
        //Cobrar multa
    }
?>
    
answered by 30.08.2017 / 18:35
source
0

You can use the date_diff () function that returns an object DateInterval with the difference of days, hours, minutes, etc.

Modified example of the PHP documentation:

<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
if($interval->d >= 5) {
    // realiza el aumento
}
?>
    
answered by 30.08.2017 в 18:24