3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); date_default_timezone_set('Europe/Berlin'); function convertToTimestamp($str) { echo "Input: " . $str . "<br>"; $str = trim($str); // date_create(), date_fromat() ab PHP 5.2.0 if (function_exists('date_create') && function_exists('date_format')) { $date = date_create($str); $x = ($date !== false) ? (int)date_format($date, 'U') : false; echo "date_create()"; var_dump( $x ); echo "Entspricht: " . date("Y-m-d H:i", $x); echo "<p><hr></p>"; return; } // Fallback mit strtotime() $ts = strtotime($str); if ($ts == -1) $ts = false; // vor PHP 5.1 kommt -1 bei Fehler echo "strtotoime()"; var_dump($ts); echo "Entspricht: " . date("Y-m-d H:i", $ts); echo "<p><hr></p>\n"; } convertToTimestamp("2012-01-01"); convertToTimestamp("2012-01-01 15:00"); convertToTimestamp("2011-02-29"); convertToTimestamp("foo"); ?>
Output for 5.2.6 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Input: 2012-01-01<br>date_create()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p>Input: 2012-01-01 15:00<br>date_create()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p>Input: 2011-02-29<br>date_create()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p>Input: foo<br>date_create()bool(false) Entspricht: 1970-01-01 01:00<p><hr></p>
Output for 5.2.0 - 5.2.5
Input: 2012-01-01<br>date_create()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p>Input: 2012-01-01 15:00<br>date_create()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p>Input: 2011-02-29<br>date_create()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p>Input: foo<br> Warning: date_create(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database in /in/0gVml on line 13 date_create()int(1346585564) Entspricht: 2012-09-02 13:32<p><hr></p>
Output for 5.1.0 - 5.1.6
Input: 2012-01-01<br>strtotoime()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p> Input: 2012-01-01 15:00<br>strtotoime()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p> Input: 2011-02-29<br>strtotoime()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p> Input: foo<br>strtotoime()bool(false) Entspricht: 1970-01-01 01:00<p><hr></p>
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/0gVml on line 4
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0gVml on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0gVml on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0gVml on line 4

preferences:
246.68 ms | 401 KiB | 369 Q