title: googlecharts php postgresql timestamp format datetime axis cleaner
body: <p>I got my application barebones up and running, but the date formatting on the bottom axis is horrible.
  <a href="https://s28.postimg.org/fts5h6fel/app.jpg" rel="nofollow noreferrer">https://s28.postimg.org/fts5h6fel/app.jpg</a></p>
  
  <p>here is my goal for the bottom axis formatting:
  <a href="https://s28.postimg.org/57qwu5y3x/app2.jpg" rel="nofollow noreferrer">https://s28.postimg.org/57qwu5y3x/app2.jpg</a></p>
  
  <p>is there a way to use the timestamp from postgresql as a datetime in googlecharts?</p>
  
  <p>currently my script imports the timestamp field as string or it does not work at all.</p>
  
  <p>postgresql db table:
  <code>
      CREATE TABLE stats(id SERIAL PRIMARY KEY, spo INTEGER NOT NULL, hr INTEGER NOT NULL, spt timestamp NOT NULL);
  </code></p>
  
  <p>example data:
  <code>
      patient=# SELECT * FROM stats LIMIT 100;
       id  | spo | hr |            spt
      -----+-----+----+----------------------------
         1 |  97 | 80 | 2017-01-01 22:39:48.606672
         2 |  96 | 79 | 2017-01-01 22:39:49.60654
         3 |  97 | 79 | 2017-01-01 22:39:50.606504
         4 |  96 | 79 | 2017-01-01 22:39:51.60639
         5 |  96 | 76 | 2017-01-01 22:39:52.606374
         6 |  96 | 74 | 2017-01-01 22:39:53.606271
         7 |  96 | 72 | 2017-01-01 22:39:54.606251
         8 |  96 | 71 | 2017-01-01 22:39:55.606124
         9 |  97 | 70 | 2017-01-01 22:39:56.606061
        10 |  97 | 69 | 2017-01-01 22:39:57.606012
  </code></p>
  
  <p>here is my current webpage:
  <code></p>
  
  <pre><code>&lt;?php
      $con = pg_connect("host=127.0.0.1 port=5432 dbname=patient user=spo password=secretpass") or die("db connection failed!");
      $sth = pg_query($con, "select spt,spo,hr from stats");
      $table = array();
      $table[] = ["spt", "spo", "hr"];
      while($r = pg_fetch_assoc($sth)) {
          $table[] = [(string) $r['spt'], (int) $r['spo'], (int) $r['hr']];
      }
      $jsonTable = json_encode($table);
      echo $jsonTable;
  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
          google.charts.load('current', {'packages':['corechart']});
          google.charts.setOnLoadCallback(drawChart);
          function drawChart() {
              var data = new google.visualization.arrayToDataTable(&lt;?=$jsonTable?&gt;);
              var options = {
                  title: 'spO2/hr monitor',
                  legend: { position: 'bottom' }
              };
              var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
              chart.draw(data, options);
          }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="curve_chart" style="width: 1200px; height: 720px"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p></code></p>