Question: My intention is to convert the following date 

`20/04/17 13:27:5` 
to this 

`20-04-2017 13:27:05`

I tried the typical date format functions of php and also Carbon...

things like

```
$newDate= Carbon::createFromFormat('d/m/y H:m:s', $originalDate);

```

in this case 
`var_dump($newDate->toDateTimeString())` would bring `2019-03-20 13:00:55` which is not what I expect.

So I was not lucky....is there a way to do this in a straight forward manner?

Answer: 
I think this should work.

```
$date = "20/04/17 13:27:5";
$sec  = substr($date, strrpos($date, ":") + 1);
$sec  = substr("0{$sec}", -2);
$new  = substr($date, 0, strrpos($date, ":") + 1) . $sec;

$newDate = Carbon::createFromFormat('d/m/y H:i:s', $new);

```

I changed the format since you were using `m` twice for "minutes" and "month". It is correct for the month, but not for the minutes. Instead use `i` for minutes with leading zeroes.

`$sec` Is what I used to get the second from the string. This gets the last position of `:` and will take everything after it. *This assumes that you do not change the format of the string*.  

`substr("0{$sec}", -2)` Adds a zero to the current second and extracts the last two characters. That means that `50` becomes `050` and then the last two characters are `50` so we end up without the padding, but `5` becomes `05` and the last two characters are the only characters.

`$new` concatenates the start of the date string and the new second with the zero padding.

`$newDate` is your original string with the format changed.
Isn't it like this?

```
$newDate = Carbon::createFromFormat('d/m/y H:i:s', $originalDate);

```