title: MYSQL Datetime to JSON to Google Charts
body: <p>I'm trying to use the Google Chart function: hAxis: {format: 'MMM, d,Y'} but I can't get it to work. And I belive it has to do with that I'm doing the conversion, from my Mysql DB to JSON wrong.</p>
  
  <p>So, how can I do this in the right manner (in this example I'm just trying to view the "Days" at the x-axis). Here is what i got so far, and thanks to <a href="https://stackoverflow.com/questions/24929767/mysql-datetime-in-google-chart">MySQL Datetime in Google Chart</a>.</p>
  
  <p>In other words, I would like the hAxis function to extract the days. So what is shown under the x-axis will only be the days.</p>
  
  <p>For clarification purpose I add a picture how it looks like right now.
  <img src="https://i.stack.imgur.com/qVDmF.jpg" alt="enter image description here">   </p>
  
  <pre><code>$rows = array();
  $table = array();
  
  $table['cols'] = array(
  array('label' =&gt; 'Time', 'type' =&gt; 'string'),
  array('label' =&gt; 'Temperature', 'type' =&gt; 'number')
  );
  
  $sql="SELECT * FROM LOG_TABLE ORDER BY ID";
  $result = mysqli_query($link,$sql);
  
  /* Extract the information from $result */
  foreach($result as $r) 
  {
    // This conversion because JSON doesen't take Date Object
    // assumes dates are patterned 'yyyy-MM-dd hh:mm:ss'
    preg_match('/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})/', $r["TIME"], $match);
    $year = (int) $match[1];
    $month = (int) $match[2] - 1; // convert to zero-index to match javascript's dates
    $day = (int) $match[3];
    $hours = (int) $match[4];
    $minutes = (int) $match[5];
    $seconds = (int) $match[6];
  
    $temp = array();
    $temp[] = array('v' =&gt; "Date($year, $month, $day, $hours, $minutes, $seconds)");
    $temp[] = array('v' =&gt; (float) $r['TEMPERATURE']);
    $rows[] = array('c' =&gt; $temp);
  }
  
  $table['rows'] = $rows;
  
  // convert data into JSON format
  $jsonTable = json_encode($table);
  </code></pre>
  
  <p>And here the rest:</p>
  
  <p>
      
      
      </p>
  
  <pre><code>// Load the Visualization API and the chart package.
  google.load('visualization', '1', {'packages':['corechart']});
  
  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);
  
  function drawChart() {
  
    // Create our data table out of JSON data loaded from server.
    var data = new google.visualization.DataTable(&lt;?=$jsonTable?&gt;);
    var options = {
         title: 'Temperature Variation',
         legend: { position: 'bottom' },
        hAxis: {format: 'd'},
        width: 800,
        height: 600
      };
    // Instantiate and draw our chart, passing in some options.
    // Do not forget to check your div ID
    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  </code></pre>