how to subtract the datetimes

24 visualizaciones (últimos 30 días)
MakM
MakM el 23 de Dic. de 2022
Editada: Stephen23 el 23 de Dic. de 2022
I have cell values that are in datetimes :
a= {[12/09/2022 04:28:01 PM]}
and
b={[12/09/2022 04:28:26 PM]}.
I want to subtract both datetimes to get the difference. I am trying it with code :
datetime(a, 'InputFormat', 'mm/dd/yyyy HH:MM:SS PM');
but it is not working.

Respuesta aceptada

Stephen23
Stephen23 el 23 de Dic. de 2022
Editada: Stephen23 el 23 de Dic. de 2022
ac = {'12/09/2022 04:28:01 PM'};
bc = {'12/09/2022 04:28:26 PM'};
at = datetime(ac, 'InputFormat','M/d/y h:m:s a')
at = datetime
09-Dec-2022 16:28:01
bt = datetime(bc, 'InputFormat','M/d/y h:m:s a')
bt = datetime
09-Dec-2022 16:28:26
bt-at
ans = duration
00:00:25
  1 comentario
MakM
MakM el 23 de Dic. de 2022
Thanks Stephan for the help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by