subtracting time - datetime

42 visualizaciones (últimos 30 días)
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama el 28 de Jul. de 2022
Comentada: Luis Eduardo Cofré Lizama el 29 de Jul. de 2022
Hi All, I'm struggling to substract the initial time from a datetime variable and get the results including milliseconds. I'n doing as below but I get "Error using datetime (line 668), Input data must be a numeric array, a string array, a cell array containing character vectors, or a char matrix.
t1 = datetime(t-t(1),'Format','hh:mm:ss.SSS');
Can you help me to figure out what's wrong?
Cheers
  2 comentarios
dpb
dpb el 28 de Jul. de 2022
Is t already a datetime variable? If so, then simply
t1=t-t(1); % t1 will now be a duration, NOT a datetime
t1.Format='hh:mm:ss.SSS';
If t it isn't a datetime, then need to know what it is; if it is a recognizable string format, then you've got to first create the datetime variable before you can subtract the first element --
t1=datetime(t,'Format','hh:mm:ss.SSS'); % create datetime -- t must be standard time format or will need 'InputFormat', too
dt=t1-t1(1); % now create the duration time variable
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama el 29 de Jul. de 2022
That was quick and effective!, t was already a datetime. Thansk works!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by