3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function convertToTimestamp($dateStr) { $dateStr = trim($dateStr); #var_dump( function_exists("date_create") ); if (!function_exists('date_create')) { return strtotime($dateStr); } $oDate = date_create($dateStr); if (is_object($oDate)) { return (int)$oDate->format('U'); } return false; } echo convertToTimestamp("2012-01-01"); // 1325376000 echo "\n"; var_dump( convertToTimestamp("foo") ); // sollte false
Output for 5.1.1 - 5.1.6, 5.2.6 - 5.2.17, 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
1325372400 bool(false)
Output for 5.4.0 - 5.4.45
Warning: date_create(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /in/5edbl on line 12 1325376000 bool(false)
Output for 5.3.0 - 5.3.29
Warning: date_create(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /in/5edbl on line 12 1325372400 bool(false)
Output for 5.2.3 - 5.2.5
1325372400 Warning: date_create(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database in /in/5edbl on line 12 int(1460558853)
Output for 5.2.2
1325372400 <br /> <b>Warning</b>: date_create() [<a href='function.date-create'>function.date-create</a>]: Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database in <b>/in/5edbl</b> on line <b>12</b><br /> int(1460558853)
Output for 5.2.0 - 5.2.1
1325372400 <br /> <b>Warning</b>: date_create() [<a href='function.date-create'>function.date-create</a>]: Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database in <b>/in/5edbl</b> on line <b>12</b><br /> int(1460558854)
Output for 5.1.0
<br /> <b>Fatal error</b>: fatal flex scanner internal error--end of buffer missed in <b>/in/5edbl</b> on line <b>22</b><br />
Process exited with code 255.
Output for 4.3.0 - 5.0.5
1325372400 int(-1)