How to go from datetime (yyyy:mm: dd hh:mm:ss) to seconds?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ilse Frans
el 4 de Jul. de 2023
Comentada: Peter Perkins
el 17 de Jul. de 2023
I have a timestamp variable with the following output (size: 1207x1):
'2023-06-27 08:31:05'
'2023-06-27 08:31:06'
'2023-06-27 08:31:07'
'2023-06-27 08:31:08'
etc.
How do I turn this into a variable where it is only seconds?
I tried the function datevec, but after every minute the seconds get to zero again, but I want the amount of seconds to continue after a minute.
Thanks in advance!
4 comentarios
Stephen23
el 4 de Jul. de 2023
Editada: Stephen23
el 5 de Jul. de 2023
MATLAB does not have a TIME2NUM function. The Predictive Maintenance toolbox has such a function.
The MATLAB approach is to use a DATETIME variable and then call TIMEOFDAY and SECONDS (all of which are actual MATLAB functions):
C = {'2023-06-27 08:31:05';'2023-06-27 08:31:06';'2023-06-27 08:31:07';'2023-06-27 08:31:08'};
T = datetime(C)
V = seconds(timeofday(T))
Peter Perkins
el 17 de Jul. de 2023
Or maybe "seconds since some origin"
C = ["2023-06-27 08:31:05";"2023-06-27 08:31:06";"2023-06-27 08:31:07";"2023-06-27 08:31:08"];
T = datetime(C)
s = T - "1-Jan-2023"; s.Format = 's'
seconds(s) % as numeric
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!