title: Create a way to search a date range from JSON datetime
body: <p>I've been battling this issue for the past few days, and I am stumped. Time to take it to you all.</p>
  
  <p>My JSON data looks like this:</p>
  
  <pre><code>{
    "apiVersion": "0.1",
    "data": {
      "offset": 0,
      "limit": 50,
      "count": 50,
      "total": 783,
      "reports": [
        {
          "type": "ROOM_CHARGE",
          "data": {
            "datetime": "2014-11-04T14:00:27-08:00",
            "originator": "639a",
            "roomNumber": "639",
            "chargeItem": "Premium Services",
            "chargeAmountCents": 495
          }
        },
        {
          "type": "STB_EVENT_TIMED",
          "data": {
            "datetime": "2014-11-04T12:58:38-08:00",
            "originator": "249b",
            "roomNumber": "249",
            "eventItem": "Watched movie 31008",
            "duration": "P0Y0M0DT1H12M18.907S"
          }
        },
  </code></pre>
  
  <p>I can display the data just fine, but I'm trying to create a way to search a date range from the <code>datetime</code> data in the JSON.</p>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>if(isset($_GET['submit_search'])){ 
    $room_number = $_GET['id'];
    $first_date = new DateTime($_GET['first_date']);
    $last_date = new DateTime($_GET['last_date']);
  }
  
  &lt;?php foreach($output1['data']['reports'] as $reporting): ?&gt;
  
      &lt;!-- inside the date range --&gt;
      &lt;?php $report_date = new DateTime($reporting['data']['datetime']); ?&gt;
      &lt;?php if($first_date &gt;= $report_date &amp;&amp; $last_date &lt;= $report_date): ?&gt;
  
          &lt;?php if($reporting['type'] == "ROOM_CHARGE"): ?&gt;
            &lt;tr&gt;
            &lt;td&gt;&lt;?php echo 'Room Charge'; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $report_date; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $report_date-&gt;format('Y-m-d'); ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $report_date-&gt;format('h:i:s A'); ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo ($reporting['data']['roomNumber']) ?&gt;  &lt;/td&gt;
            &lt;td&gt;&lt;?php echo ($reporting['data']['originator']) ?&gt;  &lt;/td&gt;                            
            &lt;td&gt;&lt;?php echo ($reporting['data']['chargeItem']) ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo number_format(($reporting['data']['chargeAmountCents'])/100, 2, '.', ',') ?&gt;&lt;/td&gt;
            &lt;td&gt;-&lt;/td&gt;              
            &lt;/tr&gt;
          &lt;?php elseif($reporting['type'] == "STB_EVENT_TIMED"): ?&gt;
            &lt;tr&gt;
            &lt;td&gt;&lt;?php echo 'Event'; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $report_date-&gt;format('Y-m-d'); ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $report_date-&gt;format('h:i:s A'); ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo ($reporting['data']['roomNumber'])?&gt;  &lt;/td&gt;
            &lt;td&gt;&lt;?php echo ($reporting['data']['originator']) ?&gt;  &lt;/td&gt;                     
            &lt;td&gt;&lt;?php echo ($reporting['data']['eventItem']) ?&gt;&lt;/td&gt;
            &lt;td&gt;-&lt;/td&gt;   
            &lt;td&gt;&lt;?php echo substr($reporting['data']['duration'], -10, 2) ?&gt;:&lt;?php echo substr($reporting['data']['duration'], -7, 2) ?&gt;:&lt;?php echo substr($reporting['data']['duration'], -4, 2) ?&gt;&lt;/td&gt;                
            &lt;/tr&gt;
          &lt;?php endif; ?&gt;
      &lt;?php endif; ?&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>the <code>$first_date</code> and <code>$last_date</code> are set to whatever a user enters in a form, in the format 2014-11-05 xxxx-xx-xx</p>
  
  <p><strong>ANY</strong> help would be appreciated. I can provide more code, or anything else you need. Thank you for checking out my post. </p>