Search code examples
phpmysqltimechartszingchart

PHP - MYSQL ZingChart Time is 7 hours ahead


ZingChart:

enter image description here

MySQL Table:

enter image description here

How do i fix this? The time in the graph doesn't match the time in the database. Any help is appreciated.

Here's the script of the graph:

    <script>
      <?php
        
        $query = "SELECT date,temperature from tb_temperature where date >= CAST(CURRENT_TIMESTAMP AS DATE)";

        $date = []; // Array to hold our date values
        $series = []; // Array to hold our series values

       $mysqli = new mysqli($host, $usernm, $passwd, $dbname, $port);
        if($mysqli->connect_error) {
          die('Connect Error (' . $mysqli->connect_errno . ')' . $mysqli->connect_error);
        }
        if ($result = $mysqli->query($query)) {
          while( $row = $result->fetch_array(MYSQLI_NUM)){

            array_push($date, $row[0]);
            array_push($series, $row[1]);
          }

    
          foreach ($date as &$value){
            $value = strtotime( $value ) * 1000;
          }

   
          $result->close();
        }
      ?>
   
      var dateValues = [<?php echo join($date, ',') ?>];
      var seriesValues = [<?php echo join($series, ',') ?>];
      <?php

        $mysqli->close(); 
      
      ?>
    </script>
    


Solution

  • It's most likely the utc offset. Whatever timezone the machine you're running this on, that's the timezone it is in. You can change this with setting utc:true and setting the timezone:7 to set the offset.

    You can inspect lines 3 & 4 of the JS tab in this demo.