title: How do two different date/time formats to determine which one is later?
body: <p>I'm getting date/time formats like this to compare:</p>
  
  <pre><code>08:18:00 07/11/2013
  
  7/11/2013 9:11:00 AM
  </code></pre>
  
  <p>How do I convert each one of them to a format so I can write PHP like this to find out which one is a later date/time?</p>
  
  <pre><code>// $time1 will always be in HH:MM:SS MM/DD/YYYY format.
  $time1 = "08:18:00 07/11/2013";
  
  // $time2 will always be in MM/DD/YYYY HH:MM:SS format.
  $time2 = "7/11/2013 9:11:00 AM";
  
  $time_one = $mytimeconvertdate_time_first($time1);
  $time_two = $mytimeconvertdate_date_first($time2);
  
  if ($time_two &gt; $time_one) {
     echo "time_two is later" . "\n";
  }  else {
     echo "time_one is later" . "\n";
  }
  </code></pre>
  
  <p>I have tried this, but the second value doesn't contain date info:</p>
  
  <pre><code>&lt;?php
  date_default_timezone_set('America/New_York');
  
  // $time1 will always be in HH:MM:SS MM/DD/YYYY format.
  $time1 = "08:18:00 07/11/2013";
  
  // $time2 will always be in MM/DD/YYYY HH:MM:SS format.
  $time2 = "7/11/2013 9:11:00 AM";
  
  $dt1 = DateTime::createFromFormat("H:i:s m/d/Y", $time1);
  $dt2 = DateTime::createFromFormat("m/d/Y H:i:s", $time2);
  var_dump($dt1);
  var_dump($dt2);
  if ($dt1 &lt; $dt2) echo "The first is earlier";
  
  ?&gt;
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>object(DateTime)#1 (3) {
    ["date"]=&gt;
    string(19) "2013-07-11 08:18:00"
    ["timezone_type"]=&gt;
    int(3)
    ["timezone"]=&gt;
    string(16) "America/New_York"
  }
  bool(false)
  </code></pre>
  
  <p>Corrected to:</p>
  
  <pre><code>&lt;?php
  date_default_timezone_set('America/New_York');
  </code></pre>
  
  <p>// Note: "One is 24-hour format while the other is 12-hour with am/pm. "</p>
  
  <pre><code>// $time1 will always be in HH:MM:SS MM/DD/YYYY format.
  $time1 = "08:18:00 07/11/2013";
  
  // $time2 will always be in MM/DD/YYYY HH:MM:SS format. 
  $time2 = "7/11/2013 9:11:00 AM";
  
  $dt1 = DateTime::createFromFormat("H:i:s m/d/Y", $time1);
  $dt2 = DateTime::createFromFormat("m/d/Y g:i:s a", $time2);
  var_dump($dt1);
  var_dump($dt2);
  if ($dt1 &lt; $dt2) echo "The first is earlier" . "\n";
  
  ?&gt;
  
  
  object(DateTime)#1 (3) {
    ["date"]=&gt;
    string(19) "2013-07-11 08:18:00"
    ["timezone_type"]=&gt;
    int(3)
    ["timezone"]=&gt;
    string(16) "America/New_York"
  }
  object(DateTime)#2 (3) {
    ["date"]=&gt;
    string(19) "2013-07-11 09:11:00"
    ["timezone_type"]=&gt;
    int(3)
    ["timezone"]=&gt;
    string(16) "America/New_York"
  }
  The first is earlier
  </code></pre>