Converting timestamp from TDMS LabView

I received measurement data using LabView as a TDMS file and use TDMS reader from https://se.mathworks.com/matlabcentral/fileexchange/30023-tdms-reader to import it. The file name itself already indicated date and time of the measurement, e.g., COP_meas1_25-01-27_1237.tdms, but the resolution was only 1 s.
Using excel with AddOn from NI, I got the following results:
From values attached to this question.
Using
datetime(timestamp(1:5),'ConvertFrom','datenum','TicksPerSecond',1e4,'Format','HH:mm:ss.SSSS')
I got the following results.
05:37:04.1507
05:37:04.1520
05:37:04.1532
05:37:04.1545
05:37:04.1557
Using
datetime(timestamp(1),'ConvertFrom','posixtime')
I got
09-Jan-1970 13:27:24
I have tried using various combinations but I failed. How should I use the parameters to get the same results as in Excel?

 Respuesta aceptada

Star Strider
Star Strider el 29 de En. de 2025
Editada: Star Strider el 29 de En. de 2025
I did not see the .mat file before, although I did look for it.
Try this —
LD = load('timestamp.mat')
LD = struct with fields:
timestamp: [1124000x1 double]
format long
timestamp = LD.timestamp
timestamp = 1124000×1
1.0e+05 * 7.396442340758194 7.396442340758338 7.396442340758482 7.396442340758628 7.396442340758773 7.396442340758917 7.396442340759061 7.396442340759206 7.396442340759351 7.396442340759496
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Time24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='+02:00')
Time24 = 1124000x1 datetime array
01/27/2025 05:37:04.150 01/27/2025 05:37:04.152 01/27/2025 05:37:04.153 01/27/2025 05:37:04.154 01/27/2025 05:37:04.155 01/27/2025 05:37:04.157 01/27/2025 05:37:04.158 01/27/2025 05:37:04.159 01/27/2025 05:37:04.160 01/27/2025 05:37:04.162 01/27/2025 05:37:04.163 01/27/2025 05:37:04.164 01/27/2025 05:37:04.165 01/27/2025 05:37:04.167 01/27/2025 05:37:04.168 01/27/2025 05:37:04.169 01/27/2025 05:37:04.170 01/27/2025 05:37:04.172 01/27/2025 05:37:04.173 01/27/2025 05:37:04.174 01/27/2025 05:37:04.175 01/27/2025 05:37:04.177 01/27/2025 05:37:04.178 01/27/2025 05:37:04.179 01/27/2025 05:37:04.180 01/27/2025 05:37:04.182 01/27/2025 05:37:04.183 01/27/2025 05:37:04.184 01/27/2025 05:37:04.185 01/27/2025 05:37:04.187
LastLine24 = Time24(end)
LastLine24 = datetime
01/27/2025 06:00:29.149
TimeAP = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy hh:mm:ss.SSS a', TimeZone='+02:00')
TimeAP = 1124000x1 datetime array
01/27/2025 05:37:04.150 AM 01/27/2025 05:37:04.152 AM 01/27/2025 05:37:04.153 AM 01/27/2025 05:37:04.154 AM 01/27/2025 05:37:04.155 AM 01/27/2025 05:37:04.157 AM 01/27/2025 05:37:04.158 AM 01/27/2025 05:37:04.159 AM 01/27/2025 05:37:04.160 AM 01/27/2025 05:37:04.162 AM 01/27/2025 05:37:04.163 AM 01/27/2025 05:37:04.164 AM 01/27/2025 05:37:04.165 AM 01/27/2025 05:37:04.167 AM 01/27/2025 05:37:04.168 AM 01/27/2025 05:37:04.169 AM 01/27/2025 05:37:04.170 AM 01/27/2025 05:37:04.172 AM 01/27/2025 05:37:04.173 AM 01/27/2025 05:37:04.174 AM 01/27/2025 05:37:04.175 AM 01/27/2025 05:37:04.177 AM 01/27/2025 05:37:04.178 AM 01/27/2025 05:37:04.179 AM 01/27/2025 05:37:04.180 AM 01/27/2025 05:37:04.182 AM 01/27/2025 05:37:04.183 AM 01/27/2025 05:37:04.184 AM 01/27/2025 05:37:04.185 AM 01/27/2025 05:37:04.187 AM
LastLineAP = TimeAP(end)
LastLineAP = datetime
01/27/2025 06:00:29.149 AM
I prefer 24-hour time. I posted conversions for both here.
I am not certain what sort of resolution you want (or what the data provide). I have them in µs here. Append more ‘S’ characters to get additional displayed precision.
The Format name-value pair determines how the datetime values are displayed. It keeps full internal precision regardless.
EDIT — (29 Jan 2025 at 13:22)
Adeded timestamp.mat file import and changed the datetime calls to accommodate it.
EDIT — (29 Jan 2025 at 14:42)
Corrected (added) time zone offset, changed seconds resolution from 6 to 3 (µs to ms). .
.

7 comentarios

Hany Ferdinando
Hany Ferdinando el 29 de En. de 2025
Maybe I didn't write my question properly. The original values were in timestamp.mat, attached to this question. I want to proses these values to get results as shown in the excel (column A).
Hany Ferdinando
Hany Ferdinando el 29 de En. de 2025
Thanks, Star. Your results were still different from the one from Excel. The first line in Excel was 12:37:04.151, while you got it as 05:37:04.150793. Do you know the source of this difference? FYI, the measurement took place in GMT+2 time zone.
Star Strider
Star Strider el 29 de En. de 2025
My pleasure!
I was going by the image, since that appeared to be what you wanted the dates and times to be. My first conversion code returned those results.
I corrected the time zones. You can change the seconds precision by changing the number of ‘S’ characters. I changed them back to three as well here, although in:
I got the following results.
05:37:04.1507
05:37:04.1520
05:37:04.1532
05:37:04.1545
05:37:04.1557
you specified at least four.
.
Hany Ferdinando
Hany Ferdinando el 29 de En. de 2025
Thank, Star. I tried it on my computer using different timezones, but the results stayed the same. Did you experience this or not?
After experiimenting with it a bit, it now seems to be working.
I have no idea what the original problem was wiith it, however changing the TimeZone after creating the datetime array works, when including it as an argument does not (although it should, according to the documentation). Also, the time itself seems to have changed, since the original file had times beginning at 12:00 and this file begins at 05:00.
Try this —
LD = load('timestamp.mat')
LD = struct with fields:
timestamp: [1124000x1 double]
format long
timestamp = LD.timestamp
timestamp = 1124000×1
1.0e+05 * 7.396442340758194 7.396442340758338 7.396442340758482 7.396442340758628 7.396442340758773 7.396442340758917 7.396442340759061 7.396442340759206 7.396442340759351 7.396442340759496
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
OriginalTime24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='Z')
OriginalTime24 = 1124000x1 datetime array
01/27/2025 05:37:04.150 01/27/2025 05:37:04.152 01/27/2025 05:37:04.153 01/27/2025 05:37:04.154 01/27/2025 05:37:04.155 01/27/2025 05:37:04.157 01/27/2025 05:37:04.158 01/27/2025 05:37:04.159 01/27/2025 05:37:04.160 01/27/2025 05:37:04.162 01/27/2025 05:37:04.163 01/27/2025 05:37:04.164 01/27/2025 05:37:04.165 01/27/2025 05:37:04.167 01/27/2025 05:37:04.168 01/27/2025 05:37:04.169 01/27/2025 05:37:04.170 01/27/2025 05:37:04.172 01/27/2025 05:37:04.173 01/27/2025 05:37:04.174 01/27/2025 05:37:04.175 01/27/2025 05:37:04.177 01/27/2025 05:37:04.178 01/27/2025 05:37:04.179 01/27/2025 05:37:04.180 01/27/2025 05:37:04.182 01/27/2025 05:37:04.183 01/27/2025 05:37:04.184 01/27/2025 05:37:04.185 01/27/2025 05:37:04.187
OT24TZ = OriginalTime24.TimeZone
OT24TZ = '+00:00'
NewTime1 = OriginalTime24;
NT1TZ = NewTime1.TimeZone
NT1TZ = '+00:00'
TZ = '+02:00';
NewTime1.TimeZone = TZ
NewTime1 = 1124000x1 datetime array
01/27/2025 07:37:04.150 01/27/2025 07:37:04.152 01/27/2025 07:37:04.153 01/27/2025 07:37:04.154 01/27/2025 07:37:04.155 01/27/2025 07:37:04.157 01/27/2025 07:37:04.158 01/27/2025 07:37:04.159 01/27/2025 07:37:04.160 01/27/2025 07:37:04.162 01/27/2025 07:37:04.163 01/27/2025 07:37:04.164 01/27/2025 07:37:04.165 01/27/2025 07:37:04.167 01/27/2025 07:37:04.168 01/27/2025 07:37:04.169 01/27/2025 07:37:04.170 01/27/2025 07:37:04.172 01/27/2025 07:37:04.173 01/27/2025 07:37:04.174 01/27/2025 07:37:04.175 01/27/2025 07:37:04.177 01/27/2025 07:37:04.178 01/27/2025 07:37:04.179 01/27/2025 07:37:04.180 01/27/2025 07:37:04.182 01/27/2025 07:37:04.183 01/27/2025 07:37:04.184 01/27/2025 07:37:04.185 01/27/2025 07:37:04.187
NT1TZ = NewTime1.TimeZone
NT1TZ = '+02:00'
NewTime2 = OriginalTime24;
NT2TZ = NewTime2.TimeZone
NT2TZ = '+00:00'
TZ = '-07:00';
NewTime2.TimeZone = TZ
NewTime2 = 1124000x1 datetime array
01/26/2025 22:37:04.150 01/26/2025 22:37:04.152 01/26/2025 22:37:04.153 01/26/2025 22:37:04.154 01/26/2025 22:37:04.155 01/26/2025 22:37:04.157 01/26/2025 22:37:04.158 01/26/2025 22:37:04.159 01/26/2025 22:37:04.160 01/26/2025 22:37:04.162 01/26/2025 22:37:04.163 01/26/2025 22:37:04.164 01/26/2025 22:37:04.165 01/26/2025 22:37:04.167 01/26/2025 22:37:04.168 01/26/2025 22:37:04.169 01/26/2025 22:37:04.170 01/26/2025 22:37:04.172 01/26/2025 22:37:04.173 01/26/2025 22:37:04.174 01/26/2025 22:37:04.175 01/26/2025 22:37:04.177 01/26/2025 22:37:04.178 01/26/2025 22:37:04.179 01/26/2025 22:37:04.180 01/26/2025 22:37:04.182 01/26/2025 22:37:04.183 01/26/2025 22:37:04.184 01/26/2025 22:37:04.185 01/26/2025 22:37:04.187
NT2TZ = NewTime2.TimeZone
NT2TZ = '-07:00'
Use the formats for either 24 Hour time or AM/PM time, as you prefer.
To do that —
NewTime1
NewTime1 = 1124000x1 datetime array
01/27/2025 07:37:04.150 01/27/2025 07:37:04.152 01/27/2025 07:37:04.153 01/27/2025 07:37:04.154 01/27/2025 07:37:04.155 01/27/2025 07:37:04.157 01/27/2025 07:37:04.158 01/27/2025 07:37:04.159 01/27/2025 07:37:04.160 01/27/2025 07:37:04.162 01/27/2025 07:37:04.163 01/27/2025 07:37:04.164 01/27/2025 07:37:04.165 01/27/2025 07:37:04.167 01/27/2025 07:37:04.168 01/27/2025 07:37:04.169 01/27/2025 07:37:04.170 01/27/2025 07:37:04.172 01/27/2025 07:37:04.173 01/27/2025 07:37:04.174 01/27/2025 07:37:04.175 01/27/2025 07:37:04.177 01/27/2025 07:37:04.178 01/27/2025 07:37:04.179 01/27/2025 07:37:04.180 01/27/2025 07:37:04.182 01/27/2025 07:37:04.183 01/27/2025 07:37:04.184 01/27/2025 07:37:04.185 01/27/2025 07:37:04.187
NewTime1AMPM = NewTime1;
NewTime1AMPM.Format = 'MM/dd/yyyy hh:mm:ss.SSS a'
NewTime1AMPM = 1124000x1 datetime array
01/27/2025 07:37:04.150 AM 01/27/2025 07:37:04.152 AM 01/27/2025 07:37:04.153 AM 01/27/2025 07:37:04.154 AM 01/27/2025 07:37:04.155 AM 01/27/2025 07:37:04.157 AM 01/27/2025 07:37:04.158 AM 01/27/2025 07:37:04.159 AM 01/27/2025 07:37:04.160 AM 01/27/2025 07:37:04.162 AM 01/27/2025 07:37:04.163 AM 01/27/2025 07:37:04.164 AM 01/27/2025 07:37:04.165 AM 01/27/2025 07:37:04.167 AM 01/27/2025 07:37:04.168 AM 01/27/2025 07:37:04.169 AM 01/27/2025 07:37:04.170 AM 01/27/2025 07:37:04.172 AM 01/27/2025 07:37:04.173 AM 01/27/2025 07:37:04.174 AM 01/27/2025 07:37:04.175 AM 01/27/2025 07:37:04.177 AM 01/27/2025 07:37:04.178 AM 01/27/2025 07:37:04.179 AM 01/27/2025 07:37:04.180 AM 01/27/2025 07:37:04.182 AM 01/27/2025 07:37:04.183 AM 01/27/2025 07:37:04.184 AM 01/27/2025 07:37:04.185 AM 01/27/2025 07:37:04.187 AM
NewTime2
NewTime2 = 1124000x1 datetime array
01/26/2025 22:37:04.150 01/26/2025 22:37:04.152 01/26/2025 22:37:04.153 01/26/2025 22:37:04.154 01/26/2025 22:37:04.155 01/26/2025 22:37:04.157 01/26/2025 22:37:04.158 01/26/2025 22:37:04.159 01/26/2025 22:37:04.160 01/26/2025 22:37:04.162 01/26/2025 22:37:04.163 01/26/2025 22:37:04.164 01/26/2025 22:37:04.165 01/26/2025 22:37:04.167 01/26/2025 22:37:04.168 01/26/2025 22:37:04.169 01/26/2025 22:37:04.170 01/26/2025 22:37:04.172 01/26/2025 22:37:04.173 01/26/2025 22:37:04.174 01/26/2025 22:37:04.175 01/26/2025 22:37:04.177 01/26/2025 22:37:04.178 01/26/2025 22:37:04.179 01/26/2025 22:37:04.180 01/26/2025 22:37:04.182 01/26/2025 22:37:04.183 01/26/2025 22:37:04.184 01/26/2025 22:37:04.185 01/26/2025 22:37:04.187
NewTime2AMPM = NewTime2;
NewTime2AMPM.Format = 'MM/dd/yyyy hh:mm:ss.SSS a'
NewTime2AMPM = 1124000x1 datetime array
01/26/2025 10:37:04.150 PM 01/26/2025 10:37:04.152 PM 01/26/2025 10:37:04.153 PM 01/26/2025 10:37:04.154 PM 01/26/2025 10:37:04.155 PM 01/26/2025 10:37:04.157 PM 01/26/2025 10:37:04.158 PM 01/26/2025 10:37:04.159 PM 01/26/2025 10:37:04.160 PM 01/26/2025 10:37:04.162 PM 01/26/2025 10:37:04.163 PM 01/26/2025 10:37:04.164 PM 01/26/2025 10:37:04.165 PM 01/26/2025 10:37:04.167 PM 01/26/2025 10:37:04.168 PM 01/26/2025 10:37:04.169 PM 01/26/2025 10:37:04.170 PM 01/26/2025 10:37:04.172 PM 01/26/2025 10:37:04.173 PM 01/26/2025 10:37:04.174 PM 01/26/2025 10:37:04.175 PM 01/26/2025 10:37:04.177 PM 01/26/2025 10:37:04.178 PM 01/26/2025 10:37:04.179 PM 01/26/2025 10:37:04.180 PM 01/26/2025 10:37:04.182 PM 01/26/2025 10:37:04.183 PM 01/26/2025 10:37:04.184 PM 01/26/2025 10:37:04.185 PM 01/26/2025 10:37:04.187 PM
Success!
.
Hany Ferdinando
Hany Ferdinando el 30 de En. de 2025
Thanks, Star! I realy appreciate your effort to help me! I just knew that we can twist the time zone after creating datetime!
Star Strider
Star Strider el 30 de En. de 2025
As always, my pleasure!
The solution was defining the TimeZone of the original as 'Z' (or equivalently, 'UTC'), although I thought that was the default. After that, defining the other time zones is straightforward.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2023b

Etiquetas

Preguntada:

el 29 de En. de 2025

Comentada:

el 30 de En. de 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by