Add days to object type DateTime

0

I have a DateTime date:

$entrada = new \DateTime($request->get('entrada'));

I need to get another date of the same type added n days.

    
asked by Armando Rodríguez Acosta 07.12.2018 в 17:55
source

2 answers

1

You can use DateInterval to add the number of days you need. Here is an example:

$fecha = new \DateTime('2018-12-07');
$agregarDias = 10;
$fecha->add(new \DateInterval("P{$agregarDias}D"));
echo $fecha->format('Y-m-d'); // 2018-12-17

The link to the official documentation is: link

    
answered by 07.12.2018 / 21:30
source
0

I hope the following code will help you

$fechauno='2018-09-27';
            $fecha = strtotime(date($fechauno));
            $start=$fecha;
            while (date ("$date",$start)>+1)
            {
                $start-=86400;
            }
            //for para obtener la segunda fecha
            for  ($i=7; $i <8; $i++)
            {
                //aquí se hace la suma de N días para obtener el resultado que se desea obtener 
             $fechados=date("Y-m-d",$start+ ($i*86400));?><br><?php
            }
    
answered by 07.12.2018 в 18:03