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: 
There is issue with seconds. There must be `05` not only `5`

```
<?php

    $original_date = "20/04/17 13:27:5";
    $date_explode = explode(":", $original_date);
    $date_explode[2] = str_pad($date_explode[2],2,"0",STR_PAD_LEFT);
    $original_date = implode($date_explode,":");

    $date = DateTime::createFromFormat('d/m/y H:i:s', $original_date);
    echo date_format($date,"d-m-Y H:i:s");

?>

```
This is a working conversion routine that creates the ISO format you are looking for. But as already mentioned you need to "fix" the strange way the seconds are specified in the original example you provide. You will have to use string functions if that *really* is the format you receive. Better would be to fix the code that creates such broken formats. 

```
<?php
$input = '20/04/17 13:27:05';
$date = DateTime::createFromFormat('d/m/y H:i:s', $input);
var_dump($date->format('d-m-Y H:i:s'));

```

The output obviously is: 

```
string(19) "20-04-2017 13:27:05"

```