title: php - Output date in d-m-Y format from MySQL timestamp column
body: <p>I have a database table which process timestamp when someone signup for my service. The timestamp works correctly and inserts whole time in database but i need only Date,Month and Year format in it. Please have a look at my code:</p>
  
  <pre><code>    if((!isset($_SESSION['USER'])) || (!isset($_SESSION['UID'])) || (!isset($_SESSION['UTYPE'])) || (($_SESSION['UTYPE']!='D') &amp;&amp; ($_SESSION['UTYPE']!='F') &amp;&amp; ($_SESSION['UTYPE']!='T')))
  {
      header( 'Location: login.html' );
  }
  else
  {
      include 'connection.php';
      include 'constants.php';
  
      $file_name = "Avanti-Website-Leads-".date('dmy-His');
  
      echo "&lt;html&gt;&lt;head&gt;";
      ?&gt;
      &lt;script src="javascript/jquery-1.9.1.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      function export2excel(file_name)
      {
          var link = document.createElement('a');
          link.download = file_name+".xls";
          link.href = 'data:application/vnd.ms-excel,' + encodeURIComponent($('body').html());
          link.click();
      }
      &lt;/script&gt;
  
      &lt;?php
  
      echo "&lt;/head&gt;&lt;body onload=\"export2excel('".$file_name."')\" &gt;";
  
      $dbh = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass);
      unset($dbhost, $dbuser, $dbpass, $dbname);
  
      if(($_SESSION['UTYPE']=='D')||($_SESSION['UTYPE']=='F'))
      {
          $query = "SELECT * FROM `bookavanti` where uid = ".$_SESSION['UID']." order by `bookavanti`.`lastupdate` DESC";
      }
      else
      {
          $query = "SELECT * FROM bookavanti order by lastupdate";
      }
  
      $sql = $dbh-&gt;prepare($query);
      $sql-&gt;execute();
      $affected_rows = $sql-&gt;rowCount();
      if($affected_rows&gt;0)
      {
          echo "&lt;table style='font-size:12px;text-align:center;'&gt;";
          echo "&lt;tr&gt;&lt;th&gt;Booking Time&lt;/th&gt;&lt;th&gt;Booking Type&lt;/th&gt;&lt;th&gt;Client Name&lt;/th&gt;&lt;th&gt;Email Address&lt;/th&gt;&lt;th&gt;Contact No.&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;Pin Code&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;/tr&gt;";
          for ($i=0; $i &lt; $affected_rows; $i++)
          {
              $row = $sql-&gt;fetch(PDO::FETCH_ASSOC);
              $x = explode('-',$row['lastupdate'],0);
              echo "&lt;tr&gt;&lt;td&gt;".date("m.d.y",$x)."&lt;/td&gt;&lt;td&gt;".$row['type']."&lt;/td&gt;&lt;td&gt;".$row['name']."&lt;/td&gt;&lt;td&gt;".$row['email']."&lt;/td&gt;&lt;td&gt;".$row['contact']."&lt;/td&gt;&lt;td&gt;".$row['address']."&lt;/td&gt;&lt;td&gt;".$row['pin']."&lt;/td&gt;&lt;td&gt;".$row['city']."&lt;/td&gt;&lt;td&gt;".$row['state']."&lt;/td&gt;&lt;/tr&gt;";
          }
          echo "&lt;/table&gt;";
      }
      echo "&lt;/body&gt;&lt;/html&gt;";
  </code></pre>
  
  <p>I believe the lines</p>
  
  <pre><code>$x = explode('-',$row['lastupdate'],0);
          echo "&lt;tr&gt;&lt;td&gt;".date("m.d.y",$x)."&lt;/td&gt;
  </code></pre>
  
  <p>have problem. What should i do to output timestamp input to d m Y format.</p>