Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AO's avatar
Level 1

format a date using formt('Y-m-d')

I have a date in my table formatted like this 02:00:00 Nov 07, 2018 PST.

format('Y-m-d') seems like not working with this kinda date.

I have the column already added to $dates[] in my model.

when I echo the date in the view I get Unexpected data found. Unexpected data found. Unexpected data found.

how I can format 02:00:00 Nov 07, 2018 PST to Y-M-D?

0 likes
2 replies
Talinon's avatar
Talinon
Best Answer
Level 51
\Carbon\Carbon::parse('02:00:00 Nov 07, 2018 PST')->format('Y-M-D');

But you likely want Y-m-d, not Y-M-D

1 like

Please or to participate in this conversation.