title: Organize Data based on Timestamp mysql + PHP
body: <p>I am trying to organize an output of DATA in the following way: 
  Today, Yesterday and everything before Yesterday is present with a respective full DateTime minus the clock time of course. For a better understanding, have a look at the screenshot below: </p>
  
  <p><img src="https://i.stack.imgur.com/GN9IB.png" alt="enter image description here"> </p>
  
  <p>I have written this code:</p>
  
  <pre><code>try{
      $db = new PDO("mysql:host=" .$hostname. ";dbname=" .$database. "", "" .$user. "", "" .$pass. "");
    $db-&gt;setAttribute(PDO::ATTR_PERSISTENT, true);
    $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
    $notifications = $db-&gt;prepare("SELECT * FROM reports
      ORDER BY timestamp DESC");
    $notifications-&gt;execute();
  
    $result = (object)$notifications-&gt;fetchAll(PDO::FETCH_OBJ);
  
    echo "&lt;pre&gt;";
  
    print_r($result);
  
      echo "&lt;/pre&gt;";
  
  }
  catch(PDOException $e)
  {
      echo $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>I am trying to figure out a way to split things up, for instance, "Today", "Yesterday", "Day before Yesterday" and so forth for as long as considered normal e.g. an entire month maybe. </p>
  
  <p>*How would I structure this up correctly with a PDO prepared statement? *</p>
  
  <pre><code>   [Today] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [timestamp] =&gt; 2015-04-09 13:20:05
              [seen] =&gt; 0
          )
      [Yesterday] =&gt; stdClass Object
          (
              [id] =&gt; 2
              [timestamp] =&gt; 2015-04-08 15:30:50
              [seen] =&gt; 0
          )
  </code></pre>
  
  <p>Clearly: I want to print everything with timestamp of TODAY. Next, everything with YESTERDAYS timestamp. And so forth.  </p>
  
  <p>SQL:</p>
  
  <pre><code>// Today
  AND DATE(from_unixtime(comment_date)) = CURRENT_DATE
  
  // Yesterday
  AND DATE(from_unixtime(comment_date)) =  DATE_SUB(CURRENT_DATE,INTERVAL 1 DAY)
  
  // This week
  AND YEARWEEK(from_unixtime(comment_date), 1) =  YEARWEEK(CURRENT_DATE, 1)
  
  // This month
  AND YEAR(from_unixtime(comment_date)) = YEAR(CURRENT_DATE)
  AND MONTH(from_unixtime(comment_date)) = MONTH(CURRENT_DATE)
  </code></pre>