There is a date in the format 'day.month.year' go 'dmY' coming to the server as a string. The date is passed as an address bar parameter.

In the controller, I need to bring it to the format 'Ymd H: i: s'

To do this, I use the following Carbon method: $ date = Carbon :: createFromFormat ('dmY', $ startDate) -> format ('Ymd H: i: s');

At the exit I get the date: $ date = "2017-05-01 17:40:26";

All would be nothing but initially in the formatted string, the time was not specified. Carbon has inserted it automatically. And the time seems to be inserted current.

I want the output of the method to be: $ date = "2017-05-01 00:00:00 "; in not "2017-05-01 17:40:26 ";

What you need to do what would be the time near the date was 00:00:00 .

  • And in the format itself, specify ...createFromFormat('dmY H:i:s', ... ? - Bookin
  • @Bookin throws the "InvalidArgumentException" error when prompted. It seems that he wanted to indicate at least some time in the formatted base line as “00:00:00” - Evgeniy Miroshnichenko
  • Honestly at first see this class)) - Bookin
  • one
    Carbon::createFromTimestamp(strtotime($startDate)) - Bookin
  • 3
    And what prevents to do so: $date = Carbon::createFromFormat('dmY', $startDate )->format('Ymd 00:00:00)'); ? - Gino Pane

0