3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Return the next month date given a date and month increment * * 2010-01-31 +1 month = 2010-02-28 not 2010-03-03 * * @todo Need to do weekdays and holiday accounting * @param string $date Date to base from in Y-m-d format * @param integer $increment Number of months to increment * @return string Date after increment */ function nextMonth($date, $increment) { // Grab the first day of month of the passed in date $firstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('first day of this month'); // Grab the last day of month of the passed in date $thirtyFirstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month'); // Just get the number of the last day $thirtyFirstOfDateMonthNum = $thirtyFirstOfDateMonth->format('d'); unset($thirtyFirstOfDateMonth); // Using the first day of month of the passed in date add month increment and get last day of that month $thirtyFirstOfNextMonth = $firstOfDateMonth; unset($firstOfDateMonth); $thirtyFirstOfNextMonth->add(new \DateInterval('P' . (int) $increment . 'M'))->modify('last day of this month'); // Just get the number of the last day $thirtyFirstOfNextMonthNum = $thirtyFirstOfNextMonth->format('d'); // Turn the passed in date into a DateTime object $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date); // Just get the number of the day $dayOfDateMonthNum = $dayOfDateMonth->format('d'); // Using the passed in date add month increment and assume correct so far $dt = $dayOfDateMonth; unset($dayOfDateMonth); $dt->add(new \DateInterval('P' . (int) $increment . 'M')); // If the last day of next month < last day of month from passed date && last day of next month < passed date day number if ($thirtyFirstOfNextMonthNum < $thirtyFirstOfDateMonthNum && $thirtyFirstOfNextMonthNum < $dayOfDateMonthNum) { // PHP has gone over the date we want so use last day of next month $dt = $thirtyFirstOfNextMonth; } unset($thirtyFirstOfNextMonth); return $dt->format('Y-m-d'); } echo nextMonth('2009-12-31', 2),"\n"; echo nextMonth('2010-01-31', 1),"\n"; echo nextMonth('2010-01-05', 1),"\n"; echo nextMonth('2010-12-05', 1),"\n"; echo nextMonth('2010-01-31', 13),"\n"; echo nextMonth('2010-01-31', 3),"\n"; echo nextMonth('2010-01-31', 0),"\n";

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.3.60.0160.00318.30
8.3.50.0130.00721.27
8.3.40.0100.00619.06
8.3.30.0060.00820.20
8.3.20.0080.00020.52
8.3.10.0080.00021.00
8.3.00.0040.00423.68
8.2.180.0090.00918.34
8.2.170.0110.01122.96
8.2.160.0070.00720.53
8.2.150.0090.00024.18
8.2.140.0050.00324.66
8.2.130.0090.00026.16
8.2.120.0040.00421.07
8.2.110.0030.00719.33
8.2.100.0080.00418.09
8.2.90.0050.00319.17
8.2.80.0000.00818.16
8.2.70.0030.00517.75
8.2.60.0090.00018.05
8.2.50.0080.00018.07
8.2.40.0030.00618.16
8.2.30.0070.00019.64
8.2.20.0000.00817.85
8.2.10.0000.00817.89
8.2.00.0000.00917.85
8.1.280.0170.00325.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00022.58
8.1.230.0110.00020.88
8.1.220.0030.00618.77
8.1.210.0030.00618.91
8.1.200.0070.00317.47
8.1.190.0040.00417.53
8.1.180.0000.00818.10
8.1.170.0000.00918.71
8.1.160.0040.00419.06
8.1.150.0030.00518.85
8.1.140.0000.00717.68
8.1.130.0030.00318.04
8.1.120.0040.00417.72
8.1.110.0040.00417.64
8.1.100.0070.00017.80
8.1.90.0000.00717.78
8.1.80.0080.00017.73
8.1.70.0030.00317.77
8.1.60.0060.00317.73
8.1.50.0080.00017.68
8.1.40.0060.00317.74
8.1.30.0030.00517.84
8.1.20.0050.00317.77
8.1.10.0000.00817.75
8.1.00.0030.00617.86
8.0.300.0040.00420.10
8.0.290.0070.00017.43
8.0.280.0040.00418.65
8.0.270.0060.00317.45
8.0.260.0000.00817.00
8.0.250.0000.00717.16
8.0.240.0060.00317.32
8.0.230.0070.00017.26
8.0.220.0070.00017.09
8.0.210.0050.00517.18
8.0.200.0030.00317.23
8.0.190.0000.00717.13
8.0.180.0000.00717.18
8.0.170.0000.00717.09
8.0.160.0000.00717.16
8.0.150.0000.00717.11
8.0.140.0070.00317.10
8.0.130.0000.00613.58
8.0.120.0080.00017.04
8.0.110.0040.00417.18
8.0.100.0040.00417.08
8.0.90.0040.00417.18
8.0.80.0150.00417.11
8.0.70.0080.00017.08
8.0.60.0040.00417.07
8.0.50.0050.00317.09
8.0.30.0130.00617.37
8.0.20.0090.01117.40
8.0.10.0040.00417.27
8.0.00.0110.00816.92
7.4.330.0000.00515.16
7.4.320.0050.00316.74
7.4.300.0000.00816.73
7.4.290.0040.00416.67
7.4.280.0070.00016.83
7.4.270.0030.00316.64
7.4.260.0060.00013.44
7.4.250.0000.00716.80
7.4.240.0030.00316.84
7.4.230.0000.00716.73
7.4.220.0110.00716.63
7.4.210.0060.01016.79
7.4.200.0040.00416.90
7.4.190.0040.00416.92
7.4.160.0090.00916.85
7.4.150.0090.00917.40
7.4.140.0090.01117.86
7.4.130.0130.00816.80
7.4.120.0060.01216.83
7.4.110.0110.00616.86
7.4.100.0120.01216.70
7.4.90.0120.00816.84
7.4.80.0140.00319.39
7.4.70.0110.00716.68
7.4.60.0120.00616.80
7.4.50.0060.00316.82
7.4.40.0060.00622.77
7.4.30.0030.01316.80
7.4.00.0110.00715.25
7.3.330.0060.00013.44
7.3.320.0030.00313.45
7.3.310.0000.00716.49
7.3.300.0040.00416.43
7.3.290.0030.01516.61
7.3.280.0080.00916.60
7.3.270.0090.00917.40
7.3.260.0130.00518.24
7.3.250.0110.01116.91
7.3.240.0130.01316.91
7.3.230.0070.01016.82
7.3.210.0130.01016.85
7.3.200.0190.00319.39
7.3.190.0150.00716.71
7.3.180.0060.00916.86
7.3.170.0150.00316.76
7.3.160.0120.01216.93
7.3.120.0070.00715.28
7.3.110.0180.00014.96
7.3.100.0070.00715.21
7.3.90.0000.01015.06
7.3.80.0090.00615.44
7.3.70.0030.01315.07
7.3.60.0060.00614.91
7.3.50.0070.01015.08
7.3.40.0030.01015.13
7.3.30.0140.00015.13
7.3.20.0090.00617.05
7.3.10.0080.01016.79
7.3.00.0080.00816.68
7.2.330.0130.01017.14
7.2.320.0070.01117.13
7.2.310.0120.00916.89
7.2.300.0120.00616.81
7.2.290.0110.01117.09
7.2.250.0070.01315.54
7.2.240.0100.01015.46
7.2.230.0040.01114.98
7.2.220.0080.00515.54
7.2.210.0060.01015.56
7.2.200.0000.01915.24
7.2.190.0000.01715.13
7.2.180.0070.01115.23
7.2.170.0100.00715.30
7.2.130.0060.00917.01
7.2.120.0040.01216.98
7.2.110.0070.01417.04
7.2.100.0220.01216.82
7.2.90.0230.00316.89
7.2.80.0190.01617.16
7.2.70.0060.01217.06
7.2.60.0110.01116.99
7.2.50.0170.00716.82
7.2.40.0160.01017.13
7.2.30.0120.00317.07
7.2.20.0110.00517.09
7.2.10.0090.00916.99
7.2.00.0050.01318.45
7.1.330.0060.00916.20
7.1.320.0060.00615.70
7.1.310.0130.00315.80
7.1.300.0090.00616.00
7.1.290.0030.01316.05
7.1.280.0030.01015.91
7.1.270.0000.01115.95
7.1.260.0070.00716.00
7.1.250.0220.00715.68
7.1.200.0060.00915.94
7.1.100.0030.00618.42
7.1.70.0000.00817.47
7.1.60.0030.01019.17
7.1.50.0210.00317.20
7.1.00.0070.05722.57
7.0.200.0000.00716.74
7.0.140.0000.07722.07
7.0.110.0100.05320.08
7.0.100.0270.04020.15
7.0.90.0170.03320.07
7.0.80.0000.05019.89
7.0.70.0330.07719.98
7.0.60.0430.06720.13
7.0.50.0330.08719.92
7.0.40.0070.07019.66
7.0.30.0070.07019.80
7.0.20.0130.07319.74
7.0.10.0100.07719.84
7.0.00.0030.07719.78
5.6.280.0100.06720.91
5.6.260.0100.05320.61
5.6.250.0000.04320.61
5.6.240.0030.05020.70
5.6.230.0030.05720.70
5.6.220.0030.08320.48
5.6.210.0070.08020.41
5.6.200.0000.07320.57
5.6.190.0030.08720.63
5.6.180.0030.08320.58
5.6.170.0030.04720.67
5.6.160.0100.03320.66
5.6.150.0130.08020.66
5.6.140.0070.06020.71
5.6.130.0070.08320.57
5.6.120.0030.08320.66
5.6.110.0070.04320.56
5.6.100.0030.03720.66
5.6.90.0030.04020.61
5.6.80.0000.08720.02
5.6.70.0030.04320.03
5.6.60.0030.04320.05
5.6.50.0100.08320.10
5.6.40.0100.07320.03
5.6.30.0200.08020.23
5.6.20.0170.07019.92
5.6.10.0030.07720.05
5.6.00.0070.07019.93
5.5.380.0030.04317.52
5.5.370.0070.04017.70
5.5.360.0030.06717.54
5.5.350.0100.03317.53
5.5.340.0070.07018.25
5.5.330.0100.08317.96
5.5.320.0070.06317.91
5.5.310.0070.04318.22
5.5.300.0100.07017.83
5.5.290.0000.09018.09
5.5.280.0070.08318.09
5.5.270.0070.08318.11
5.5.260.0270.06318.09
5.5.250.0170.03017.74
5.5.240.0100.07017.48
5.5.230.0030.07717.46
5.5.220.0100.07717.29
5.5.210.0070.04717.29
5.5.200.0030.04017.58
5.5.190.0070.07717.45
5.5.180.0030.08017.58
5.5.160.0070.06717.45
5.5.150.0070.03717.40
5.5.140.0100.03317.26
5.5.130.0170.08017.57
5.5.120.0070.07717.31
5.5.110.0030.08317.47
5.5.100.0100.07317.31
5.5.90.0030.04017.16
5.5.80.0130.06717.38
5.5.70.0070.04717.17
5.5.60.0070.04017.15
5.5.50.0030.07317.37
5.5.40.0030.04017.07
5.5.30.0100.05317.36
5.5.20.0030.05317.46
5.5.10.0030.05317.46
5.5.00.0100.06317.19
5.4.450.0100.08019.32
5.4.440.0100.04719.52
5.4.430.0100.10019.34
5.4.420.0070.07319.50
5.4.410.0170.06719.44
5.4.400.0030.07319.01
5.4.390.0000.05719.01
5.4.380.0130.06719.31
5.4.370.0000.04319.09
5.4.360.0030.06319.05
5.4.350.0030.07719.23
5.4.340.0000.04718.98
5.4.320.0030.05719.32
5.4.310.0030.06019.31
5.4.300.0030.08319.00
5.4.290.0070.07719.36
5.4.280.0070.05719.31
5.4.270.0030.03319.24
5.4.260.0100.06719.09
5.4.250.0030.04318.99
5.4.240.0100.07318.98
5.4.230.0170.07019.17
5.4.220.0130.07319.00
5.4.210.0070.04019.30
5.4.200.0130.04719.02
5.4.190.0100.03719.30
5.4.180.0030.07319.15
5.4.170.0030.08318.98
5.4.160.0170.06018.99
5.4.150.0030.08018.96
5.4.140.0070.08016.37
5.4.130.0030.08316.58
5.4.120.0070.07316.36
5.4.110.0070.07016.38
5.4.100.0030.06716.49
5.4.90.0030.03716.37
5.4.80.0030.07316.55
5.4.70.0030.06716.26
5.4.60.0100.07016.54
5.4.50.0070.07016.34
5.4.40.0100.07016.52
5.4.30.0100.07016.49
5.4.20.0100.05716.48
5.4.10.0070.04316.53
5.4.00.0030.03315.80
5.3.290.0100.04714.64
5.3.280.0070.05314.61
5.3.270.0030.08014.63
5.3.260.0100.07014.70
5.3.250.0070.07314.63
5.3.240.0130.05314.61
5.3.230.0000.08314.70
5.3.220.0070.06014.46
5.3.210.0130.08314.57
5.3.200.0100.04714.66
5.3.190.0070.04014.57
5.3.180.0000.04014.63
5.3.170.0030.06714.54
5.3.160.0270.05714.59
5.3.150.0070.08014.70
5.3.140.0030.08014.53
5.3.130.0100.05014.52
5.3.120.0070.06014.64
5.3.110.0070.06714.57
5.3.100.0030.03714.15
5.3.90.0030.04014.04
5.3.80.0130.06314.03
5.3.70.0030.07713.88
5.3.60.0130.07313.99
5.3.50.0000.08013.93
5.3.40.0100.06714.11
5.3.30.0100.05013.91
5.3.20.0170.05713.70
5.3.10.0070.03013.66
5.3.00.0070.03013.69
5.2.170.0000.03312.16
5.2.160.0030.02712.16
5.2.150.0000.04712.16
5.2.140.0070.03312.16
5.2.130.0030.05312.16
5.2.120.0030.02712.16
5.2.110.0070.02712.16
5.2.100.0030.05712.16
5.2.90.0100.05712.16
5.2.80.0070.06312.16
5.2.70.0100.02712.16
5.2.60.0030.05712.16
5.2.50.0100.04712.16
5.2.40.0030.05712.16
5.2.30.0030.04712.16
5.2.20.0000.05712.16
5.2.10.0000.05712.16
5.2.00.0030.06312.16
5.1.60.0100.04712.16
5.1.50.0000.04312.16
5.1.40.0030.02712.16
5.1.30.0100.04312.16
5.1.20.0000.05712.16
5.1.10.0070.05012.16
5.1.00.0030.04012.16
5.0.50.0030.02312.16
5.0.40.0070.01712.16
5.0.30.0030.04712.16
5.0.20.0000.03012.16
5.0.10.0030.04312.16
5.0.00.0000.06312.16
4.4.90.0030.03012.16
4.4.80.0000.03312.16
4.4.70.0000.03712.16
4.4.60.0070.03012.16
4.4.50.0030.01312.16
4.4.40.0070.04712.16
4.4.30.0000.02712.16
4.4.20.0000.03012.16
4.4.10.0100.02312.16
4.4.00.0000.05012.16
4.3.110.0030.01712.16
4.3.100.0000.01712.16
4.3.90.0070.02012.16
4.3.80.0070.03012.16
4.3.70.0000.01712.16
4.3.60.0000.01712.16
4.3.50.0000.02712.16
4.3.40.0000.03312.16
4.3.30.0030.02712.16
4.3.20.0000.03012.16
4.3.10.0030.02712.16
4.3.00.0030.03012.16

preferences:
35.41 ms | 401 KiB | 5 Q