1

I have the following code:

        $d = str_replace('at', '', '08-24-2016 at 11:18 AM');
        $d = strtotime($d);
        $postdate = date('Y-d-m H:i:s',$d);
        echo $postdate;

It returns: 1970-01-01 00:00:00 just dates older than this. If I change it to today. It works fine. Any ideas?

Any idea how to convert that date properly?

Miro
  • 8,402
  • 3
  • 34
  • 72
  • 3
    Use `DateTime::createFromFormat` instead. http://php.net/manual/en/datetime.createfromformat.php – Charlotte Dunois Oct 04 '16 at 19:47
  • if you replace **-** with **/** it would work "Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. " –  Oct 04 '16 at 19:49
  • @CharlotteDunois tried it and it doesn't work `DateTime::createFromFormat('m-d-Y h:i:s A', $d);` returns nothing... – Miro Oct 04 '16 at 19:54
  • 1
    Well, because there are no seconds in your code. https://3v4l.org/ZSNjA – Charlotte Dunois Oct 04 '16 at 19:56
  • 1
    I'm an idiot! You're golden :) Thank you so much! – Miro Oct 04 '16 at 19:57

0 Answers0