0

How would I change the date 18/08/2018 10:46:15 pm to Sat 25, 10:46:15 pm in PHP. I am doing the following:

```

$OldDate = "18/08/2018 10:46:15 pm";
$NewDate = $OldDate->format(D-j, Y-H:I:S);
echo $NewDate;

?>```

However, it is not showing anything, am I formatting it correctly?

James Smith
  • 95
  • 1
  • 2
  • 7

1 Answers1

0

Your old date is just a string. If you want to format it, you need to create a DateTime object using that string the constructor.

You're also incorrectly specifying the format

$OldDate = new DateTime("18/08/2018 10:46:15 pm");
echo $OldDate->format("L-j, h:i:s A");

http://php.net/manual/en/class.datetime.php

HorusKol
  • 8,375
  • 10
  • 51
  • 92