3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseDate($dateValue) { $dateFormats = array( 'D, d M y H:i:s T', 'D, d M Y H:i:s T', 'D, d-M-y H:i:s T', 'D, d-M-Y H:i:s T', 'D, d-m-y H:i:s T', 'D, d-m-Y H:i:s T', 'D M j G:i:s Y', 'D M d H:i:s Y T', ); foreach ($dateFormats as $dateFormat) { if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) { return $date; } } return date_create($dateValue, new \DateTimeZone('GMT')); } $dates = array( array('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 GMT'), array('Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 GMT'), ); foreach ($dates as $date) { echo parseDate($date[0])->format(\DateTime::COOKIE) . "\n"; }
Output for 5.5.10 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Friday, 31-Jul-2020 08:49:37 GMT Friday, 31-Jul-2020 08:49:37 GMT
Output for 5.4.24 - 5.4.45, 5.5.8 - 5.5.9
Friday, 31-Jul-2020 08:49:37 GMT Friday, 31-Jul-2020 08:49:37 UTC
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.23, 5.5.0 - 5.5.7
Friday, 31-Jul-20 08:49:37 GMT Friday, 31-Jul-20 08:49:37 UTC
Output for 5.2.10 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 29 Fatal error: Call to undefined method DateTime::createFromFormat() in /in/VpvRp on line 16
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 29 Fatal error: Call to undefined method DateTime::createfromformat() in /in/VpvRp on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 29 Fatal error: Class 'DateTime' not found in /in/VpvRp on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/VpvRp on line 29
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/VpvRp on line 29
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VpvRp on line 21 Parse error: parse error, expecting `','' or `';'' in /in/VpvRp on line 29
Process exited with code 255.

preferences:
88.21 ms | 418 KiB | 5 Q