I want to format date where I get from SQL Server where data type is date (not datetime).
I have tried add date casting in model like this:
class MyModel extends Model
{
protected $casts = [
'date' => 'date:Y',
];
}
but there is an error:
Could not parse 'Apr 20 2021 12:00:00:AM': DateTime::__construct(): Failed to parse time string (Apr 20 2021 12:00:00:AM) at position 20 (:)
When I change data type in SQL Server to datetime, there was worked perfectly.
I have tried any parsing method (in accessor) use Carbon or date('d-m-Y', strtotime($date)), there still error when data type is date but working well when data type is datetime.
Any suggestions? Thanks.