php date_create_from_format
function accepting non-existent, though format-valid dates.
i function behave date
command:
niloct@hp-mini:~$ date --date="29/02/2011" +%s date: invalid date `29/02/2011'
though happens in php:
$tmp = date_create_from_format('d/m/y h:i:s',"29/02/2011 00:00:00", timezone_open('america/sao_paulo')); var_dump($tmp); /* output: object(datetime)#28 (3) { ["date"]=> string(19) "2011-03-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(17) "america/sao_paulo" } */
can automatic conversion avoided , function return -1
in case ?
niloct@hp-mini:~$ php -v php 5.3.3-1ubuntu9.3 suhosin-patch (cli) (built: jan 12 2011 16:08:14)
thank you.
you can use combination of date_parse_from_format
, checkdate
see if it's valid calendar date.
example:
$date = date_parse_from_format('d/m/y h:i:s',"29/02/2011 00:00:00"); if (checkdate($date['month'], $date['day'], $date['year'])) { echo "valid date"; } else { echo "invalid date"; }
Comments
Post a Comment