Getting a "timestamp" of when data is collected is entirely down to you.

Most Arduinos don't have any concept of the current time, only the time since the program started running. To know what the time "now" is you have to have some mechanism to tell the Arduino what the time is, along with a method of keeping track of that time.

There are devices called Real-Time Clock (RTC) modules which keep track of the time for you. They don't magically know the time - you still have to tell them at least once.

You could tell it the time through the serial port to set the clock - from then on (assuming the RTC has power) the RTC will know what the time is.

Another option to get the time into the RTC is to use an internet connection (ESP8266, WiFi shield, Ethernet shield, etc) to perform a Network Time Protocol (NTP) query to a time server on the internet (such as pool.ntp.org) to get the current time and update the RTC. This should be done regularly to correct any drift in the RTC.

Once you have an RTC and a method of setting the time you can query the time whenever you sample some data and store that time along with the data in whatever way is most suitable for your situation.

Answer from Majenko on Stack Exchange
🌐
Circuit Basics
circuitbasics.com › using-an-arduino-ethernet-shield-for-timekeeping
How to Get the Date and Time on an Arduino
October 22, 2024 - The response packet contains a timestamp at byte 40 to 43. This timestamp is the number of seconds elapsed since NTP epoch ( 01 January 1900 ). To get the current UTC time, we just need to subtract the seconds elapsed since the NTP epoch from ...
🌐
GitHub
github.com › Erriez › ErriezTimestamp
GitHub - Erriez/ErriezTimestamp: Timestamp library for Arduino · GitHub
Any Arduino / ESP8266 board. ... Timestamp with microseconds resolution example Printing this message takes: 768us And this message takes: 2044us delayMicroseconds(15) duration: 20us analogRead() duration: 212us digitalRead() duration: 4us
Starred by 3 users
Forked by 2 users
Languages   C++
Discussions

Time stamping the sensor output
Hi everyone, I wanted to know how to timestamp my sensor output in the serial monitor so that I may get the reading against the corrosponding date and time. I don't want to use the RTC chip for this purpose and I want the sketch to sync the arduino with the computer clock. More on forum.arduino.cc
🌐 forum.arduino.cc
11
0
May 31, 2015
Creating an timestamp ?
I dont have code because I cant work out how to do this. The functional requirement though are these. 1.) Given a year, month, day, hour,minute and second I want to return a timestamp 2.) Given that timestamp I want to add 7 days to it and get the new timestamp. More on forum.arduino.cc
🌐 forum.arduino.cc
5
0
September 27, 2024
Uno using timestamp
When I ask for a time stamp along with my sensor data, it appears nicely on the serial monitor screen just like the text supplied by my sensors. BUT, when I read the data coming across the serial port (using python) the timestamp does not show. I am assuming it is sent to the serial monitor ... More on forum.arduino.cc
🌐 forum.arduino.cc
12
0
August 20, 2024
Millis vs Timestamp
Hello, I apologize for the basic question but I am wondering if this would be the preferred process for you all. I am just getting my feet wet and this forum has been super helpful in the past. I have been using the serial timestamp with my data coming from the Nano 33 BLE, typically the readings ... More on forum.arduino.cc
🌐 forum.arduino.cc
19
0
July 14, 2021
Top answer
1 of 2
2

Getting a "timestamp" of when data is collected is entirely down to you.

Most Arduinos don't have any concept of the current time, only the time since the program started running. To know what the time "now" is you have to have some mechanism to tell the Arduino what the time is, along with a method of keeping track of that time.

There are devices called Real-Time Clock (RTC) modules which keep track of the time for you. They don't magically know the time - you still have to tell them at least once.

You could tell it the time through the serial port to set the clock - from then on (assuming the RTC has power) the RTC will know what the time is.

Another option to get the time into the RTC is to use an internet connection (ESP8266, WiFi shield, Ethernet shield, etc) to perform a Network Time Protocol (NTP) query to a time server on the internet (such as pool.ntp.org) to get the current time and update the RTC. This should be done regularly to correct any drift in the RTC.

Once you have an RTC and a method of setting the time you can query the time whenever you sample some data and store that time along with the data in whatever way is most suitable for your situation.

2 of 2
1

It depends on how you define the time stamp. A Unix timestamp is the number of seconds elapsed since Unix epoch time, i.e. January 1 1970 00:00 UTC, this is a very common time stamp. You can setup with NTP via the internet, or you can use a RTC on your board. How you do it depends on how accurate you want it and what you have available. Try this link it may help: https://currentmillis.com/

🌐
YouTube
youtube.com › watch
Arduino Serial Monitor Timestamps: demo and explanations - YouTube
The "Show timestamp" feature in the Arduino Serial Monitor (IDE version 1.8.8 and above) tells us when the PC receives strings from the Arduino's Serial. In ...
Published   January 13, 2019
🌐
Arduino Forum
forum.arduino.cc › other hardware › sensors
Time stamping the sensor output - Sensors - Arduino Forum
May 31, 2015 - Hi everyone, I wanted to know how to timestamp my sensor output in the serial monitor so that I may get the reading against the corrosponding date and time. I don't want to use the RTC chip for this purpose and I want t…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Creating an timestamp ? - Programming - Arduino Forum
September 27, 2024 - I dont have code because I cant work out how to do this. The functional requirement though are these. 1.) Given a year, month, day, hour,minute and second I want to return a timestamp 2.) Given that timestamp I want to…
🌐
GitHub
gist.github.com › dhhagan › f1cca00cdb479558b6d1
Print a timestamp to SD card on Arduino · GitHub
Print a timestamp to SD card on Arduino · Raw · print-timestamp-arduino · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
Codebender
codebender.cc › example › SdFat › Timestamp
Library example: SdFat : Timestamp
<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/example/SdFat/Timestamp" frameborder="0"></iframe> You can also embed the Serial Monitor section! Just use this HTML code. <iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe> ... This example was tested on 2016-06-11 and it compiles on Arduino Uno, Arduino Leonardo, Arduino Mega
🌐
Arduino Getting Started
arduinogetstarted.com › tutorials › arduino-log-data-with-timestamp-to-sd-card
Arduino - Log Data with Timestamp to SD Card | Arduino Getting Started
1 week ago - /* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-log-data-with-timestamp-to-sd-card */ #include <SD.h> #include <RTClib.h> #define PIN_SPI_CS 4 #define FILE_NAME "log.txt" RTC_DS3231 rtc; File myFile; void setup() { Serial.begin(9600); // SETUP RTC MODULE if (!rtc.begin()) { Serial.println(F("Couldn't find RTC")); while (1); } if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD CARD FAILED, OR NOT PRESENT!")); while (1); // don't do anything more: } Serial.println(F("SD CARD INITIALIZED.")); Ser
🌐
Arduino
arduino.cc › reference › en › libraries › timestamp32bits
timestamp32bits - Arduino Reference
May 8, 2022 - This library allows to generate 32 bits timestamps that are compatible with valid current UNIX timestamps for the time period between 1/1/1970 and 2/7/2106 06:28:15. Now it also allows to generate custom timestamps specifying the EPOCH year. ... This library is compatible with all architectures ...
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › getting date and time with esp32 on arduino ide (ntp client)
Getting Date and Time with ESP32 (NTP Client) | Random Nerd Tutorials
June 12, 2024 - In this tutorial we’ll show you how to get date and time using the ESP32 and Arduino IDE. Getting date and time is especially useful in data logging to timestamp your readings.
🌐
Erriez
erriez.github.io › ErriezTimestamp
Erriez Timestamp library for Arduino: Timestamp measuring library for Arduino
https://www.arduino.cc/reference/en/language/functions/time/millis/ The timestamp functions introduce a small calling overhead on low-end microcontrollers. For example calling start() and delta() on an Arduino UNO may take an additional 4 to 8 microseconds.
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Uno using timestamp - General Guidance - Arduino Forum
August 20, 2024 - When I ask for a time stamp along with my sensor data, it appears nicely on the serial monitor screen just like the text supplied by my sensors. BUT, when I read the data coming across the serial port (using python) th…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Millis vs Timestamp - Programming - Arduino Forum
July 14, 2021 - I am just getting my feet wet and this forum has been super helpful in the past. I have been using the serial timestamp with my data coming from the Nano 33 BLE, typically the readings are 17:46:27.316, 17:46:27.420, 17:46:27.529... etc.
🌐
Arduino
docs.arduino.cc › language-reference › en › functions › time › millis
millis() | Arduino Documentation
Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. Use the following function to get the exact time the board has been running the current program in milliseconds: ... This function does not admit parameters. This function returns the number of milliseconds passed since the program started. Data type: ... This example code prints on the serial port the number of milliseconds passed since the Arduino board started running the code itself...
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › get epoch/unix time with the esp32 (arduino)
Get Epoch/Unix Time with the ESP32 (Arduino) | Random Nerd Tutorials
February 16, 2021 - Learn how to request Epoch time or Unix time using the ESP32 board with Arduino IDE. Getting the epoch time can be useful to timestamp your readings, etc...
🌐
Arduino
docs.arduino.cc › libraries › timestamp32bits
Arduino
The Arduino environment can be extended through the use of libraries. Libraries provide extra functionality for use in sketches. To use a library in a sketch, select it from Sketch > Import Library.
🌐
PJRC
pjrc.com › teensy › td_libs_DateTime.html
DateTime Arduino Library, timekeeping and time data manipulation on Teensy
PJRC Store Teensy 3.0, $19 Teensy 2.0, $16 Teensy++ 2.0, $24 USB Cable, $4 Teensy Main Page Getting Started How-To Tips Code Library Projects Teensyduino Main Tutorial Download+Install Basic Usage Digital I/O PWM & Tone Timing USB Serial USB Keyboard USB Mouse USB Joystick USB MIDI USB Flight ...
🌐
Arduino
playground.arduino.cc › Code › DateTime
Arduino Playground - DateTime
August 8, 2022 - The date and time needs to be set ... as a computer connected via the serial port. Once synchronized the Arduino crystal provides accuracy within a few seconds per day. The download includes an example sketch and a readme.txt file to explain the basics of adding a ...