Hi All
I want to change the date displayed on the graph from the tutorial.
Visualize Your Sensor Readings from Anywhere in the World (ESP32/ESP8266 + MySQL + PHP)
I just want to show the Month, day, hour and minute. not year and seconds.
TIA
I believe that comes from the variable $readings_time. Where it is set you have the opportunity to display what you want. There is a commented section that allows you to change time zone. You can also change the format using the PHP date function and date_format string.
Hi Sara
I might need some help here as I’m a bit of a newby.
Which do I change and what would be the code
I found reading_time in the SQL table query.
and this in esp-chart.php
$readings_time = array_column($sensor_data, 'reading_time');
Hi Sara
What would I change here to get Sydney Australia time zone and no year or seconds.
$readings_time = array_column($sensor_data, ‘reading_time’);
// ******* Uncomment to convert readings time array to your timezone ********
/*$i = 0;
foreach ($readings_time as $reading){
// Uncomment to set timezone to – 1 hour (you can change 1 to any number)
$readings_time[$i] = date(“Y-m-d H:i:s”, strtotime(“$reading – 1 hours”));
// Uncomment to set timezone to + 4 hours (you can change 4 to any number)
//$readings_time[$i] = date(“Y-m-d H:i:s”, strtotime(“$reading + 4 hours”));
$i += 1;
}*/
Hello Patto, in Sydney Australia the timezone is (GMT+10)
as you’ve stated you need to change it like this in the esp-chart.php file:
// ******* Uncomment to convert readings time array to your timezone ********
$i = 0;
foreach ($readings_time as $reading){
// Uncomment to set timezone to + 10 hours (you can change 10 to any number)
$readings_time[$i] = date("Y-m-d H:i:s", strtotime("$reading + 10 hours"));
$i += 1;
}
Does that work for you?
Regards,
Rui
Note also the date format string in Rui’s code “Y-m-d H:i:s”. This is what you would change to get your month, day, hour and minute. Find the right string to use from date_format (Hint: “F” gives you a full textual representation of a month, such as January or March)
So awesome Rui and Steve
Thanks so much for you help. Both worked perfectly and I have exactly what I want at the bottom,
Its still a little crowded. Can I get the chart to put the date on say the first reading of the day and then only the time on the rest of the readings, or even only put the time on the first reading of the hour.
Something like
29 june 12:00
01:00
02:00
etc
Thanks so much for your help. Its been invaluable.