how to subtract the datetimes

11 views (last 30 days)
MakM
MakM on 23 Dec 2022
Edited: Stephen23 on 23 Dec 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.

Accepted Answer

Stephen23
Stephen23 on 23 Dec 2022
Edited: Stephen23 on 23 Dec 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

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!