Subtract days in php

0

Tengon in a variable the days of expiration and I have to make it show the days that are missing to win.

<?php
$fechaApertura = '02/08/2018';
$fechaVencimiento = '08/11/2018';
$dias = 6; //6 dias por vencer
$restaDias = $fechaVencimiento - $dias;
echo "Faltan ".$restaDias." dias para el vencimiento";
?>

What results in 2 days, but in reality there are still 6. I do not know how to do it and a thousand apologies for that.

    
asked by Stn 03.11.2018 в 02:40
source

1 answer

1

You can use the following procedure:

<?php
$fechaApertura = date_create('2018-08-02');
$fechaVencimiento = date_create('2018-11-08');
$interval = date_diff($fechaApertura, $fechaVencimiento);
echo $interval->format('%R%a días');
?>
    
answered by 03.11.2018 / 02:46
source