Search code examples
laravelphp-carbon

Why Carbon::createFromForma returns invalid date?


In laravel 8 app converting string datetime from string into datetime with carbon

$date= Carbon::createFromFormat('m/d/Y H:m', ‘09/02/2021 05:56’, config('app.timezone') );


I got unexpected value in $date= ‘2025-08-02 05:00:00.000000’

but not current day as I expected and I do not see error in my format string?

Which way is correct ?

Thanks!


Solution

  • $date= Carbon::createFromFormat('m/d/Y H:m', ‘09/02/2021 05:56’, config('app.timezone') );
    

    Minute is i, not m in 'm/d/Y H:m'.

    Also, you have apostrophes instead of quotes in ‘09/02/2021 05:56’, but I guess that's only in this post since it would cause a PHP parse error.