3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function validaData($date, $format = 'Y-m-d H:i:s') { $v_date = date_create_from_format($format, $date); $v_date = date_format($v_date, $format); return ($v_date && $v_date == $date); } var_dump(validaData('2014-02-28 12:12:12')); # true var_dump(validaData('2014-02-30 12:12:12')); # false var_dump(validaData('2014-2-28', 'Y-m-d')); # true var_dump(validaData('28/02/2014', 'd/m/Y')); # true var_dump(validaData('30/02/2014', 'd/m/Y')); # false var_dump(validaData('14:50', 'H:i')); # true var_dump(validaData('14:77', 'H:i')); # false var_dump(validaData(14, 'H')); # true var_dump(validaData('14', 'H')); # true
Output for 5.5.0 - 5.6.28, 7.0.0 - 7.1.0
bool(true) bool(false) bool(false) bool(true) bool(false) bool(true) bool(false) bool(true) bool(true)
Output for hhvm-3.10.0 - 3.12.0
bool(true) bool(false) bool(false) bool(true) bool(false) bool(true) bool(false) Catchable fatal error: Argument 2 passed to date_create_from_format() must be an instance of string, int given in /in/JP7DW on line 4
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true)
Output for 5.3.0 - 5.3.29
Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(false) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true) Warning: date_create_from_format(): 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/JP7DW on line 4 bool(true)
Output for 5.2.3 - 5.2.17
Fatal error: Call to undefined function date_create_from_format() in /in/JP7DW on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.2.2
<br /> <b>Fatal error</b>: Call to undefined function date_create_from_format() in <b>/in/JP7DW</b> on line <b>4</b><br />
Process exited with code 255.
Output for 5.1.0
<br /> <b>Fatal error</b>: fatal flex scanner internal error--end of buffer missed in <b>/in/JP7DW</b> on line <b>17</b><br />
Process exited with code 255.
Output for 4.4.5 - 4.4.9
<br /> <b>Fatal error</b>: Call to undefined function: date_create_from_format() in <b>/in/JP7DW</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.4.4
<br /> <b>Fatal error</b>: Call to undefined function: date_create_from_format() in <b>/in/JP7DW</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<br /> <b>Fatal error</b>: Call to undefined function: date_create_from_format() in <b>/in/JP7DW</b> on line <b>4</b><br />