3v4l.org

run code in 300+ PHP versions simultaneously
<?php function friendlyDtmDiff($date1, $date2, $length = '', $format = '') { // Create DateTime for diff() $dt1 = new \DateTime($date1); $dt2 = new \DateTime($date2); // Create intervals if ($dt1 < $dt2) { $sign = ''; $interval = $dt1->diff($dt2); } else { $sign = '-'; $interval = $dt2->diff($dt1); } // Output format (minimum 2 digits for upper case formats) $of = ($format < 'a') ? '%02d' : '%d'; // generate output using an array of terms to be imploded $output = array(); // create time components switch ($format) { case 'Y': case 'y': $years = $interval->y; if ($years) $output[] = sprintf("$of years", $years); if ($length != 'l') break; $interval->y = 0; case 'M': case 'm': $months = $interval->y * 12 + $interval->m; if ($months) $output[] = sprintf("$of months", $months); if ($length != 'l') break; $interval->m = $interval->y = 0; case 'D': case 'd': $days = ($interval->y * 12 + $interval->m) * 30 + $interval->d; if ($days) $output[] = sprintf("$of days", $days); if ($length != 'l') break; $interval->d = $interval->m = $interval->y = 0; case 'H': case 'h': $hours = (($interval->y * 12 + $interval->m) * 30 + $interval->d) * 24 + $interval->h; if ($hours) $output[] = sprintf("$of hours", $hours); if ($length != 'l') break; $interval->h = $interval->d = $interval->m = $interval->y = 0; case 'I': case 'i': $minutes = ((($interval->y * 12 + $interval->m) * 30 + $interval->d) * 24 + $interval->h) * 60 + $interval->i; if ($minutes) $output[] = sprintf("$of minutes", $minutes); if ($length != 'l') break; $interval->i = $interval->h = $interval->d = $interval->m = $interval->y = 0; case 'S': case 's': $seconds = (((($interval->y * 12 + $interval->m) * 30 + $interval->d) * 24 + $interval->h) * 60 + $interval->i) * 60 + $interval->s; if ($seconds) $output[] = sprintf("$of seconds", $seconds); break; default: return 'Invalid format'; break; } // put the output string together $last = array_pop($output); return $sign . (count($output) ? implode(', ', $output) . ' and ' : '') . $last; } echo friendlyDtmDiff('2020-02-28 00:00:00', '2020-03-01 12:00:56', '', 'h') . PHP_EOL; echo friendlyDtmDiff('2020-02-28 00:00:00', '2020-03-01 12:00:56', 'l', 'h') . PHP_EOL; echo friendlyDtmDiff('2020-02-28 00:00:00', '2020-03-01 12:08:56', 'l', 'h') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 'y') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 'm') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 'd') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 'h') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 'i') . PHP_EOL; echo friendlyDtmDiff('2018-12-28 00:00:00', '2020-04-11 04:08:56', 'l', 's') . PHP_EOL;

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.10.0060.00318.26
8.3.140.0090.00916.84
8.3.130.0060.00318.45
8.3.120.0030.00620.77
8.3.110.0090.00618.68
8.3.100.0030.00617.01
8.3.90.0070.01118.71
8.3.80.0060.00317.97
8.3.70.0090.00616.88
8.3.60.0070.01418.68
8.3.50.0180.01117.57
8.3.40.0090.00619.14
8.3.30.0080.00818.96
8.3.20.0050.00322.54
8.3.10.0040.00420.33
8.3.00.0030.00623.44
8.2.260.0030.00520.83
8.2.250.0040.01116.96
8.2.240.0150.00417.11
8.2.230.0140.00720.94
8.2.220.0040.00424.06
8.2.210.0120.00626.77
8.2.200.0060.00318.56
8.2.190.0070.00716.63
8.2.180.0110.00718.66
8.2.170.0070.01322.96
8.2.160.0100.00320.50
8.2.150.0100.00024.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0000.00819.95
8.2.110.0100.00019.21
8.2.100.0040.00818.09
8.2.90.0060.00318.00
8.2.80.0030.00618.29
8.2.70.0080.00018.17
8.2.60.0040.00418.47
8.2.50.0040.00418.10
8.2.40.0060.00319.72
8.2.30.0000.00719.36
8.2.20.0000.00818.20
8.2.10.0000.00719.49
8.2.00.0000.00721.25
8.1.310.0090.00616.96
8.1.300.0090.00616.10
8.1.290.0000.00918.88
8.1.280.0100.01025.92
8.1.270.0040.00420.93
8.1.260.0080.00026.35
8.1.250.0080.00328.09
8.1.240.0090.00321.95
8.1.230.0000.01220.97
8.1.220.0040.00417.89
8.1.210.0000.00818.77
8.1.200.0030.00517.72
8.1.190.0030.00617.73
8.1.180.0000.01018.10
8.1.170.0050.00318.84
8.1.160.0000.00819.16
8.1.150.0040.00419.10
8.1.140.0050.00221.05
8.1.130.0000.00720.33
8.1.120.0070.00017.65
8.1.110.0030.00617.75
8.1.100.0000.00817.79
8.1.90.0020.00517.75
8.1.80.0000.00817.79
8.1.70.0030.00317.76
8.1.60.0030.00517.70
8.1.50.0040.00417.79
8.1.40.0000.00917.75
8.1.30.0000.00817.93
8.1.20.0030.00617.80
8.1.10.0040.00417.77
8.1.00.0000.00817.78
8.0.300.0040.00419.98
8.0.290.0050.00317.13
8.0.280.0040.00418.67
8.0.270.0000.00717.46
8.0.260.0070.00020.16
8.0.250.0000.01017.19
8.0.240.0070.00317.25
8.0.230.0030.00417.13
8.0.220.0030.00317.07
8.0.210.0070.00017.20
8.0.200.0070.00017.31
8.0.190.0050.00317.12
8.0.180.0000.00817.04
8.0.170.0050.00317.11
8.0.160.0040.00417.09
8.0.150.0000.00817.16
8.0.140.0030.00517.13
8.0.130.0030.00313.58
8.0.120.0030.00617.04
8.0.110.0030.00517.16
8.0.100.0030.00517.14
8.0.90.0050.00317.17
8.0.80.0120.01117.24
8.0.70.0040.00417.25
8.0.60.0030.00617.07
8.0.50.0040.00417.13
8.0.30.0090.01117.42
8.0.20.0120.00917.37
8.0.10.0080.00017.27
8.0.00.0140.00416.96
7.4.330.0000.00615.55
7.4.320.0060.00016.75
7.4.300.0030.00316.82
7.4.290.0030.00316.82
7.4.280.0000.00816.82
7.4.270.0030.00316.79
7.4.260.0060.00013.45
7.4.250.0000.00916.84
7.4.240.0010.00716.68
7.4.230.0050.00216.81
7.4.220.0050.00216.70
7.4.210.0070.00816.72
7.4.200.0000.00716.86
7.4.130.0090.01016.79
7.4.120.0090.00916.74
7.4.110.0060.01316.69
7.4.100.0060.01516.81
7.4.90.0110.00616.70
7.4.80.0120.00819.39
7.4.70.0070.01016.78
7.4.60.0030.01416.74
7.4.50.0050.00916.59
7.4.40.0060.01016.81
7.3.330.0000.00816.58
7.3.320.0030.00313.39
7.3.310.0050.00216.48
7.3.300.0030.00316.38
7.3.290.0100.00516.47
7.3.280.0150.00716.46
7.3.260.0110.00816.80
7.3.240.0060.01416.72
7.3.230.0070.01016.52
7.3.210.0100.00716.83
7.3.200.0090.01516.59
7.3.190.0100.01016.74
7.3.180.0060.01016.83
7.3.170.0030.01416.59
7.3.160.0070.01016.72
7.3.80.0080.00414.81
7.3.70.0090.00614.79
7.3.60.0070.01115.06
7.3.50.0090.00914.79
7.3.40.0040.00815.02
7.3.30.0130.00015.04
7.3.20.0170.00014.99
7.3.10.0120.01215.11
7.3.00.0170.00815.06
7.2.330.0090.00916.88
7.2.320.0120.01016.87
7.2.310.0060.01216.90
7.2.300.0030.01616.99
7.2.290.0000.01616.80
7.2.210.0040.00815.38
7.2.200.0070.00715.18
7.2.190.0110.00715.09
7.2.180.0070.01115.28
7.2.170.0080.00815.26
7.2.160.0030.01315.41
7.2.150.0180.00615.21
7.2.140.0200.00915.04
7.2.130.0180.00615.36
7.2.120.0240.00015.18
7.2.110.0150.00815.25
7.2.100.0150.00915.30
7.2.90.0110.00715.37
7.2.80.0140.01015.05
7.2.70.0210.00415.41
7.2.60.0070.01615.12
7.2.50.0180.00915.47
7.2.40.0130.00715.23
7.2.30.0120.00815.31
7.2.20.0170.00315.43
7.2.10.0140.01015.16
7.2.00.0210.00415.39
7.1.310.0110.00714.07
7.1.300.0370.01013.91
7.1.290.0160.00414.29
7.1.280.0710.01014.19
7.1.270.0050.01413.77
7.1.260.0110.01114.06
7.1.250.0150.00814.10

preferences:
28.24 ms | 403 KiB | 5 Q