title: PHP Fatal error: Call to a member function diff() on a non-object in... comparing DateTime from database
body: <p>Im trying to compare two different DateTime and get the difference. </p>
  
  <p>Im getting this error PHP Fatal error:  Call to a member function diff() on a non-object in... when trying to run/compile my code but cant figure out what I'm doing wrong.</p>
  
  <pre><code>$datetime = date("Y-m-d H:i:s");
  $localhost = "localhost";
  $conn = mysqli_connect($localhost, $mysqlUsername, $mysqlPassword, $mysqlDB);
  
  if (!$conn)
  {
          die("Connection failed: " . mysqli_connect_error());
          echo "Connection to DB failed";
  }
  
  $sql = "SELECT * FROM UniqueUsers";
  $result = mysqli_query($conn, $sql);
  
  if ($result-&gt;num_rows &gt; 0 )
  {
          while($row = $result-&gt;fetch_assoc())
          {
                  $datetime1 = new DateTime($row['worldtime']);
                  $interval = $datetime-&gt;diff($datetime1);
                  echo $interval-&gt;format('%R%a days');
          }
  }
  </code></pre>