PHP: strtotime returns "nothing" like "boolean"

I have a variable $EDate, I used the strtotime function with this variable with different values, and the result was as follows:

$EDate = 10-21-2013;    echo "strtotime($EDate)";   the result = nothing    and the type is boolean
$EDate = 09-02-2013;    echo "strtotime($EDate)";   the result = 1360386000 and the type is integer
$EDate = 09-30-2013;    echo "strtotime($EDate)";   the result = nothing    and the type is boolean
$EDate = 09-30-2013;    echo "strtotime($EDate)";   the result = nothing    and the type is boolean
$EDate = 07-02-2014;    echo "strtotime($EDate)";   the result = 1391749200 and the type is integer
$EDate = 10-12-2014;    echo "strtotime($EDate)";   the result = 1418187600 and the type is integer

Can someone explain this and how to avoid a logical result?

+4
source share
2 answers

From the documentation :

Dates in m / d / y or dmy formats are resolved ambiguously by considering the separator between the various components: if the separator is a slash (/), then the American m / d / y is assumed; whereas if the delimiter is a dash (-) or a period (.), then the European dmy format is assumed.

, d-m-y FALSE, :

var_dump(strtotime('10-21-2013')); // no month 21
var_dump(strtotime('09-30-2013'));
var_dump(strtotime('09-30-2013'));

, DateTime::createFromFormat():

$date = DateTime::createFromFormat('m-d-Y', '10-21-2013');
echo $date->format('U');

!

+3

: , . .

, :

$EDate = '10-21-2013'; 
...

: 10 - 12 - 2013 = -2015.

+3

All Articles