Search code examples
laravellaravel-5php-carbon

Carbon return InvalidArgumentException for a particular format conversion


I have a date returned from a javascript library in the format 23/10/2019 12:03:46 and while saving in the database i am trying to convert into a carbon object like below:-

 $order->delivery_date =  Carbon::createFromFormat('dd/mm/Y H:i:s',$request->time);

getting error

InvalidArgumentException: Unexpected data found.

also tried these similar links link1 link2 but not able to get out of this problem.


Solution

  • the format string seems to be wrong. Try it like this:

    $order->delivery_date = Carbon::createFromFormat('d/m/Y H:i:s',$request->time);