adamreeve / npTDMS

NumPy based Python module for reading TDMS files produced by LabView

Home Page:http://nptdms.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DateTime adjustment when reading TDMS files from Python

AShahLab opened this issue · comments

commented

I have a TDMS file with a bunch of DateTime values with relevant instrumentation data.
The issue I am having is:

TDMS file >>>> Python Reads
4/20/2021 12:00:01 AM >>>> 2021-04-20 04:00:00.597573
4/20/2021 8:00:01 PM >>>> 2021-04-21 00:00:00.570708
This is messing up transfers to the database because it is not accurate.

This is my code:

dfscaled = tdmsfile.__getitem__("Data (Scaled)").as_dataframe()  
for index, row in dfscaled.iterrows():
     print(row["Timestamp"])

I am using the NPTDMS library. Could this issue be resolved?

Hi, TDMS files internally store times in UTC. You don't say how you're getting the values in the "TDMS file" column but I assume this is from a program that converts times into your local timezone to display them. There is an example of how to convert UTC times from a TDMS file into your local timezone in the documentation.

If you are storing these times in a database though, I would strongly recommend you store times in UTC rather than your local timezone as local times can be ambiguous due to daylight savings changes, and UTC is easily understood from anywhere in the world without having to know the local timezone where the data originated.