3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date = DateTime::createFromFormat( "Y-m-d", "2025-01-31", new DateTimeZone('UTC') ); echo $date->format('Y-m-d'); echo PHP_EOL; $date->add( new DateInterval('P1M') ); echo $date->format('Y-m-d'); echo PHP_EOL; echo PHP_EOL; $date2 = DateTimeImmutable::createFromFormat( "Y-m-d", "2025-01-31", new DateTimeZone('UTC') ); echo "Current date is : " . $date2->format( 'Y-m-d'); $currentMonth = $date2->format('m'); $nextMonth = $date2->add( new DateInterval('P1M') )->format('m'); if( $currentMonth == $nextMonth-1 && $date2->format('j') != $date2->format('t') ) { $nextDate = $date2->add( new DateInterval('P1M') ); } else { $nextDate = $date2->modify( "last day of next month" ); } echo PHP_EOL; /* $currentMonth = date("m",strtotime($date)); $nextMonth = date("m",strtotime($date."+1 month")); if($currentMonth==$nextMonth-1 && (date("j",strtotime($date)) != date("t",strtotime($date)))){ $nextDate = date('Y-m-d',strtotime($date." +1 month")); }else{ $nextDate = date('Y-m-d', strtotime("last day of next month",strtotime($date))); }*/ echo "Next date would be : {$nextDate->format( 'Y-m-d')}"; echo PHP_EOL; echo PHP_EOL; function addOneMonth( DateTimeImmutable $date ): DateTimeImmutable { $currentMonth = $date->format('m'); $nextMonth = $date->add( new DateInterval('P1M') ); if( $currentMonth == $nextMonth->modify( '-1 month')->format( 'm') && $date->format('j') != $date->format('t') ) { $nextDate = $date->add( new DateInterval('P1M') ); } else { $nextDate = $date->modify( "last day of next month" ); } return $nextDate; } function addOneMonth2( DateTimeImmutable $date ): DateTimeImmutable { $nextMonth = $date->add( new DateInterval('P1M') ); if ($date->format('d') > $nextMonth->format('d')) { return $date->modify('last day of this month'); } else { return $nextMonth; } } $startDate = DateTimeImmutable::createFromFormat( "Y-m-d", "2024-01-01", new DateTimeZone('UTC') ); $dates = []; for( $i = 0; $i < 368; $i++) { $nextDate = $startDate->add( new DateInterval("P{$i}D") ); echo $nextDate->format('Y-m-d'); echo " - "; $nextMonthStart = addOneMonth2( $nextDate ); $endOfPrevMonth = $nextMonthStart->modify( '-1 day' ); echo $endOfPrevMonth->format('Y-m-d'); $daysDiff = $nextDate->diff($endOfPrevMonth)->days + 1; if( $daysDiff > 31 || $daysDiff < 29 ) { echo "PROBLEM!!!!"; } echo " ({$daysDiff}) "; echo " "; echo $nextMonthStart->format('Y-m-d'); echo " "; $nextMonthStartMonthStr = ( (int) $nextDate->format('n') + 1); $nextMonthStartString = $nextDate->format("Y") . "-" . $nextMonthStartMonthStr . "-" . $nextDate->format("d"); echo " comparing {$nextMonthStart->format('Y-n-d')} to {$nextMonthStartString} "; if( $nextMonthStart->format( 'Y-n-d') !== $nextMonthStartString ) { echo "PROBLEM!!!!"; } echo PHP_EOL; $dates[] = $nextDate; } //print_r($dates);

Abusive script

This script was stopped while abusing our resources

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.100.0190.01418.06
8.4.90.0220.00818.10
8.4.80.0140.01319.63
8.4.70.0090.00717.83
8.4.60.0150.01719.48
8.4.50.0440.01518.02
8.4.40.0500.01417.91
8.4.30.0380.01317.68
8.4.20.0370.01217.59
8.4.10.0390.01517.57
8.3.230.0160.01217.07
8.3.220.0130.00816.68
8.3.210.0130.01216.75
8.3.200.0130.01616.91
8.3.190.0460.01016.68
8.3.180.0400.01416.76
8.3.170.0370.01116.49
8.3.160.0340.02016.50
8.3.150.0450.01417.02
8.3.140.0350.01616.87
8.3.130.0420.01116.80
8.3.120.0390.01416.67
8.3.110.0250.00616.76
8.3.100.0500.01216.60
8.3.90.0400.01016.99
8.3.80.0300.00916.98
8.3.70.0490.01116.98
8.3.60.0390.01116.71
8.3.50.0180.00817.03
8.3.40.0170.00517.95
8.3.30.0190.00718.01
8.3.20.0310.01017.98
8.3.10.0320.01917.75
8.3.00.0190.01517.77
8.2.280.0360.01016.75
8.2.270.0320.01316.94
8.2.260.0380.01716.75
8.2.250.0200.00816.61
8.2.240.0230.01116.96
8.2.230.0140.00917.03
8.2.220.0140.01116.44
8.2.210.0410.01216.89
8.2.200.0370.01416.50
8.2.190.0460.00716.73
8.2.180.0390.01316.81
8.2.170.0350.01018.11
8.2.160.0340.00917.96
8.2.150.0420.01318.09
8.2.140.0240.00518.00
8.2.130.0130.00918.00
8.2.120.0180.00717.89
8.2.110.0180.00617.90
8.2.100.0200.00917.76
8.2.90.0160.01018.11
8.2.80.0190.01017.81
8.2.70.0270.00917.92
8.2.60.0260.01118.07
8.2.50.0160.01017.83
8.2.40.0180.00818.11
8.2.30.0070.00617.97
8.2.20.0150.01418.08
8.2.10.0060.00818.01
8.2.00.0050.00817.95

preferences:
52.29 ms | 403 KiB | 5 Q