• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Change Date on graph

Q&A Forum › Category: ESP32 › Change Date on graph
0 Vote Up Vote Down
Patto asked 4 years ago

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

8 Answers
0 Vote Up Vote Down
Steve Mercer answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Patto.
Does Steve’s suggestion help?
Regards,
Sara

0 Vote Up Vote Down
Patto answered 4 years ago

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');
0 Vote Up Vote Down
Patto answered 4 years ago

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;
}*/

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

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:

  • https://raw.githubusercontent.com/RuiSantosdotme/Visualize-ESP32-ESP8266-Readings-Anywhere/master/code/esp-chart.php
// ******* 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

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

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)

0 Vote Up Vote Down
Patto answered 4 years ago

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.

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Hello again and I’m glad it helped.
Unfortunately the way that the highcharts.js library works is not that easy to implement that feature in the graph by default… At least I don’t know any method built-in that allows you to do that…
Regards,
Rui

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.