3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('America/New_York'); function date_to_unix($date){ $date = DateTime::createFromFormat('Ymd', $date); return $date->getTimestamp(); } function unix_to_date($unix){ $date = DateTime::createFromFormat('U', $unix); $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); return $date->format('Ymd'); } $originalDate = '20140525'; $timeStamp = date_to_unix($originalDate); $newDate = unix_to_date($timeStamp); echo "$originalDate gives a timestamp of $timeStamp which converts back to $newDate";
Output for 5.3.0 - 5.4.4, 5.4.6 - 7.3.1
20140525 gives a timestamp of 1401002959 which converts back to 20140525
Output for 5.4.5
20140525 gives a timestamp of 1401002960 which converts back to 20140525
Output for 5.2.10 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined method DateTime::createFromFormat() in /in/vD5ll on line 5
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined method DateTime::createfromformat() in /in/vD5ll on line 5
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Class 'DateTime' not found in /in/vD5ll on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined function date_default_timezone_set() in /in/vD5ll on line 2
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined function: date_default_timezone_set() in /in/vD5ll on line 2
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined function: date_default_timezone_set() in /in/vD5ll on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vD5ll on line 11 Fatal error: Call to undefined function: date_default_timezone_set() in /in/vD5ll on line 2