3v4l.org

run code in 500+ PHP versions simultaneously
<?php $start_date = (new DateTime('2023-05-01')); $end_date = (new DateTime('2023-07-15'))->modify('last day of this month'); $interval = $start_date->diff($end_date); $months = $interval->format('%m'); $months_property = $interval->m; echo "months format: $months"; echo "\nmonths_property: $months_property"; //echo "\n".$start_date->format('Y-m-d H:i:s'); //echo "\n".$end_date->format('Y-m-d H:i:s');
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
months format: 2 months_property: 2
Output for 8.0.1 - 8.0.30
months format: 3 months_property: 3

preferences:
30.58 ms | 1139 KiB | 9 Q