How to get timestamp of when the data was collected
Getting a &quot;timestamp&quot; 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 &quot;now&quot; 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.