Reputation: 170
I have a url param that looks like the following:
http://url?date=2017-01-01,2017-03-12
I am then exploding the string on the ,
$date = explode(',', $request->query('date'));
When i dump out the string its fine.
array:2 [▼
0 => "2017-01-01"
1 => "2017-03-12"
]
I then generate the date
$dateOne = date('Y-m-d',strtotime($date[0]));
This returns: 1970-01-01
but if do the second element of the array
$dateOne = date('Y-m-d',strtotime($date[1]));
I get a nice formatted date 2017-03-12
I am so confused how this is happening.....
Any ideas?
Upvotes: 1
Views: 100
Reputation: 824
The problem is the format of your data, strtotime function consider the date format by the separator character, in your case is the dash "-". So, strtotime consider the date format d-m-y. Replace the separator with a point "." and you solve the problem.
Ref: http://php.net/manual/it/function.strtotime.php#100144
Upvotes: 2