Strange Date Function Behavior

Today I came across this question in StackOverflow, but did not receive an answer.

My question

echo date('Ym-d',strtotime('2012-september-09')); // output - 2012-09-01 echo date('Ym-d',strtotime('09-september-2012')); // output - 2012-09-09 

Codepad

I am confused by why the first format does not give the correct answer. Any help?

+4
source share
3 answers

From manual :

if the delimiter is a slash (/), then American m / d / y is assumed; whereas if the separator is a dash (-) or a period (.), then the European dmy format is assumed.

+6
source

This is not the behavior of the date function, but << 21>. strtotime can only process dates in certain formats listed in the Date Formats man page. 09-september-2012 is in the format dd ([ \t.-])* m ([ \t.-])* y specified there, but 2012-september-09 does not match any of the supported formats.

+4
source

I think in your code,

 echo date('Ym-d',strtotime('2012-september-09')); 

strtotime('2012-september-09') not a valid format ('2012-September-09') for the strtotime() date function.

link to this link http://www.php.net/manual/en/datetime.formats.date.php

+1
source

Source: https://habr.com/ru/post/1432446/


All Articles