Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

Carbon date parsing issue in laravel

I am using Laravel 5.6, PHP 7.2.10

2018-12-24 12:42:00.0 is getting converted to "Dec 24 2018, 12:12 pm"

Output of tinker

$dt = App\Video::find(8611)->created_at;
=> Illuminate\Support\Carbon @1545655320 {#3075
     date: 2018-12-24 12:42:00.0 UTC (+00:00),
   }
>>> Carbon\Carbon::parse($dt)->format('M d Y, h:m a')
=> "Dec 24 2018, 12:12 pm"
>>>

what I am missing or doing wrong or this is any known behavior of carbon.

Upvotes: 0

Views: 1865

Answers (3)

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

Working format is

$dt->format('Y-m-d H:i a')

Upvotes: 1

Nabil Farhan
Nabil Farhan

Reputation: 1536

Instead of

format('M d Y, h:m a')

try

format('Y-m-d H:i:s.u')

Upvotes: 1

tienhien1102
tienhien1102

Reputation: 67

Hope help you:

 Carbon\Carbon::parse($dt, 'YYYY-MM-DD HH:mm:ss')->format('M d Y, h:m a')

Upvotes: 0

Related Questions