martes, 9 de mayo de 2017

PHP : Sumar o Restar dias a una fecha ( add or subtract days to a date in PHP )

Esta es una manera muy fácil de sumar o restar días a una fecha en PHP, solo hay que utilizar la función strtotime.

This is a very easy way to add or subtract days to a date in PHP, just use the function strtotime.

Veamos el ejemplo. Let's see the example: 


$fecha = date('Y-m-d');
$fechaNueva = strtotime ('+2 day' , strtotime ($fecha));
$fechaNueva = date ('Y-m-d' , $fechaNueva );
echo $fechaNueva ;

Para restar días a la fecha solo hay que agregar el signo menos.
To subtract the days to the date you only have to add the minus sign.

veamos el ejemplo. Let's see the example: 


$fecha = date('Y-m-d');
$fechaNueva = strtotime ('-2 day' , strtotime ($fecha));
$fechaNueva = date ('Y-m-d' , $fechaNueva );
echo $fechaNueva ;

No hay comentarios.:

Publicar un comentario