Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/01/2011, 21:43
Avatar de bng5
bng5
 
Fecha de Ingreso: junio-2009
Ubicación: 127.0.0.1
Mensajes: 269
Antigüedad: 14 años, 10 meses
Puntos: 24
Respuesta: suma de fechas

Código PHP:
Ver original
  1. <?php
  2.  
  3. //fecha inicial 2011-01-15
  4. $fecha = new DateTime('2011-01-15');
  5. //tiempo 2 meses
  6. $meses = 2;
  7.  
  8. for($i = 0; $i < $meses; $i++) {
  9.     $fecha->modify('+1 month');
  10.     echo $fecha->format('Y-m-d')."\n";
  11. }
  12.  
  13. echo "\n";
  14.  
  15. //otro ejemplo
  16. //fecha inicial 2011-01-01
  17. $fecha = new DateTime('2011-01-01');
  18. //tiempo 3 meses
  19. $meses = 3;
  20.  
  21. for($i = 0; $i < $meses; $i++) {
  22.     $fecha->modify('+1 month');
  23.     echo $fecha->format('Y-m-d')."\n";
  24. }
  25.  
  26. ?>

Imprime:

Código:
2011-02-15
2011-03-15

2011-02-01
2011-03-01
2011-04-01