MattB
2 months ago
432
5
Laravel

DateTime::__construct(): Failed to parse time string (02-2020) at position 0 (0): Unexpected character

Posted 2 months ago by MattB

I'm storing just a month and year in my db which stores it as a string such as this for example:

02-2020

I'm trying to turn it into a month and date using carbon so hopefully it looks like this:

February 2020

I'm using this line of code to do it:

{{ $newsflash->date->createFromFormat('MM YYYY') }}

But get error

DateTime::__construct(): Failed to parse time string (02-2020) at position 0 (0): Unexpected character

I'm not sure what's happening, or what the character is I'm messing up with. Any help would be massively appreciated. I do have the following in my model which allows it to be manipulated:

protected $dates = ['date'];

Please sign in or create an account to participate in this conversation.