PHP Laravel - Undefined property: DateTime::$format
Hello,
I'm used to using a custom format from datetime like below. When I try it in the Laravel framework, I can't. Can you advise how to achieve the datetime format? Thank you
Error 1 (format)
-----------------------------
ErrorException
Undefined property: DateTime::$format
Error 2 (isoFormat)
-----------------------------
Unknown getter 'isoFormat'
Hi,
You can format the datetime in the Laravel framework using Carbon, for example, as follows:
I'm used to using a custom format from datetime like below. When I try it in the Laravel framework, I can't. Can you advise how to achieve the datetime format? Thank you
Error 1 (format)
-----------------------------
$now = new DateTime;
$now->format('Y')
ErrorException
Undefined property: DateTime::$format
Error 2 (isoFormat)
-----------------------------
$now = Carbon::now();
$now->isoFormat('dddd D')
Unknown getter 'isoFormat'
REPLY
Hi,
You can format the datetime in the Laravel framework using Carbon, for example, as follows:
$now = Carbon::now()->format('d.m.Y');