<?php
//Enter your code here, enjoy!
$fechaMIN = "2010-01-01";
$fechaMAX = "2011-05-31";
$ts1 = strtotime( $fechaMIN );
$ts2 = strtotime( $fechaMAX );
$year1 = date( 'Y', $ts1 );
$year2 = date( 'Y', $ts2 );
$month1 = date( 'm', $ts1 );
$month2 = date( 'm', $ts2 );
$day1 = date( 'd', $ts1 );
$day2 = date( 'd', $ts2 );
$month1_days = date( 't', $ts1 );
$month2_days = date( 't', $ts2 );
$d1 = new DateTime( date( 'Y-m-d', $ts1 ) );
$d2 = new DateTime( date( 'Y-m-d', strtotime( $fechaMAX .' +1 day') ) );
$diff = $d2->diff( $d1, true );
$month2_days = (int) date( 't ', $d2->getTimestamp() );
echo "$fechaMIN >> $fechaMAX >>>> " . date( 'Y-m-d ', $d1->getTimestamp() ) . ' >> ' . date( 'Y-m-d ', $d2->getTimestamp() ) ;
$diff_months = round( $diff->y * 12 + $diff->m + ( ( $diff->d ) / $month2_days ), 6 );
echo " >>> ". $diff_months .PHP_EOL;
- Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- 2010-01-01 >> 2011-05-31 >>>> 2010-01-01 >> 2011-06-01 >>> 17
preferences:
172.55 ms | 404 KiB | 204 Q