Question: I have a function that prints out:

```
echo $post->EE_Event->primary_datetime()->start_date_and_time();

```

result:

```
21-02-15 08:00

```

But i want to display it as:

```
08:00 21st February, 2015

```

I need help with a function to grab the existing printed out date and reformat it.

I have tried a few snippets online, but nothing that worked.

Answer: 
PHP's [`DateTime`](http://php.net/DateTime) class has exactly what you need. You want to use the [`createFromFormat`](http://php.net/manual/en/datetime.createfromformat.php) to parse it in, then use [`format`](http://php.net/manual/en/datetime.format.php) to print it back out.

```
$myDate = $post->EE_Event->primary_datetime()->start_date_and_time();
$myDateObj = DateTime::createFromFormat('d-m-y G:i', $myDate);

echo $myDateObj->format('G:i jS F, Y');

```
```
echo date("G:i dS F, Y", strtotime($post->EE_Event->primary_datetime()->start_date_and_time()));

```