how to subtract the datetimes

11 visualizzazioni (ultimi 30 giorni)
MakM
MakM il 23 Dic 2022
Modificato: Stephen23 il 23 Dic 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.

Risposta accettata

Stephen23
Stephen23 il 23 Dic 2022
Modificato: Stephen23 il 23 Dic 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

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by