Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/08/2018, 08:59
tuadmin
 
Fecha de Ingreso: abril-2006
Mensajes: 583
Antigüedad: 17 años, 11 meses
Puntos: 120
Respuesta: ¿Cómo poder listar los meses y su año transcurridos entre dos fechas?

Cita:
Iniciado por dfmex Ver Mensaje
¡Hola amigos!

¿Alguien podría decirme si existe alguna función en PHP que me permita listar el mes y su año transcurridos entre dos fechas?

Por ejemplo:

Código PHP:
$FechaInicial 2018-06-01;
$FechaFinal 2018-08-30


Junio 2018
Julio 2018
Agosto 2018

Si alguien pudiera darme un empujoncito se lo agradecería mucho...
en la pagina oficial de PHP lo tienes

http://php.net/manual/es/datetime.add.php
dentro de los comentarios de USUARIOS
Código PHP:
<?php

$dt 
= new DateTime("2016-01-31");

$oldDay $dt->format("d");
$dt->add(new DateInterval("P1M")); // 2016-03-02
$newDay $dt->format("d");

if(
$oldDay != $newDay) {
    
// Check if the day is changed, if so we skipped to the next month.
    // Substract days to go back to the last day of previous month.
    
$dt->sub(new DateInterval("P" $newDay "D"));
}

echo 
$dt->format("Y-m-d"); // 2016-02-29