Search code examples
phpdatedate-conversion

creating date from format php


Trying to convert a date with the format Jul 27, 2015 5:42:05 PM This is the current way that I'm trying to create the date from the format that I've been provided.

$newDate = new DateTime::createFromFormat('m d, y H:i:s', $game->createDate);

It doesn't like the way that I'm currently doing it. Do I need to try and rework the way that the date comes to me?

This is how I am printing it currently echo date_format($newDate, 'Y-m-d');


Solution

  • createFromFormat is a static method. You don't new it:

    $new = DateTime::createFromFormat(...);
    

    it'll do the new business for you internally.