Reputation: 2108
I'm, trying to format a date into (Dayname Date Month) and I'm using Carbon for this but it return an error Carbon The format separator does not match here is a sample of DB data 2017-02-09 18:30:00.
Below is my code
Carbon::createFromFormat('l j F', $matchArr['matchTime'])->toDateTimeString()
Upvotes: 1
Views: 6691
Reputation: 560
Assuming the value you're passing as your 2nd argument is a string 2017-02-09 18:30:00
, Carbon will throw this error because the format you've specified as the 1st argument - l j F
- doesn't match the format of the value you're passing as your 2nd argument.
2017-02-09 18:30:00
has format Y-m-d H:i:s
- i.e. the following should work:
Carbon::createFromFormat('Y-m-d H:i:s', '2017-02-09 18:30:00');
N.B. 1: In Carbon, the error
The format separator does not match
often comes up if you mix up your order of arguments - i.e. if you put the time, followed by the format. (Thought this was worth worth mentioning for anyone else who comes across this - an easy mistake to make!)
N.B. 2: Carbon uses the same date time formatting as native PHP DateTime: https://www.php.net/manual/en/datetime.format.php
Upvotes: 3
Reputation: 2108
So I just end up using native date function
date('l j F', strtotime($matchArr['matchTime']))
Upvotes: 1
Reputation: 949
to convert DB date "2017-02-09 18:30:00" to (Dayname Date Month) just use the php date function:
date("D d M", strtotime("2017-02-09 18:30:00"));
//outputs "Thu 09 Feb"
date("D d M", strtotime($matchArr['matchTime']);
Upvotes: 4