0

I've been struggling with this for a while now. How would I change this code to get my reading_time into millisecond for a highstock chart to read it. Currently my reading_time looks like 2021-08-07 17:59:42 but the chart is reading 0000-00-00 00:00:00 as I need the datetime in unix. I have tried chaning the format in JS but that doesnt help. Im trying to get my chart to use a rangeselector but with the wrong date type it doesnt work

<?php

$servername = "localhost";

$dbname = "";
$username = "";
$password = "";



$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, value1, reading_time FROM Sensor order by reading_time desc limit 40";

$result = $conn->query($sql);

while ($data = $result->fetch_assoc()){
    $sensor_data[] = $data;
}

$readings_time = array_column($sensor_data, 'reading_time');

$i = 0;
foreach ($readings_time as $reading){
    $readings_time[$i] = date("d-M H:i", strtotime("$reading + 16 hours"));
  $i += 1;
}

$value1 = json_encode(array_reverse(array_column($sensor_data, 'value1')), JSON_NUMERIC_CHECK);
$reading_time = json_encode(array_reverse($readings_time), JSON_NUMERIC_CHECK);

/*echo $value1;
echo $reading_time;*/

$result->free();
$conn->close();
?>
<?php

$servername = "localhost";

$dbname = "";
$username = "";
$password = "";



$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, value1, reading_time FROM Sensor order by reading_time desc limit 40";

$result = $conn->query($sql);

while ($data = $result->fetch_assoc()){
    $sensor_data[] = $data;
}

$readings_time = array_column($sensor_data, 'reading_time');

$i = 0;
foreach ($readings_time as $reading){
    $readings_time[$i] = date("d-M H:i", strtotime("$reading + 16 hours"));
  $i += 1;
}

$value1 = json_encode(array_reverse(array_column($sensor_data, 'value1')), JSON_NUMERIC_CHECK);
$reading_time = json_encode(array_reverse($readings_time), JSON_NUMERIC_CHECK);

/*echo $value1;
echo $reading_time;*/

$result->free();
$conn->close();
?>

0 Answers0