how to subtract the datetimes

22 次查看(过去 30 天)
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.

采纳的回答

Stephen23
Stephen23 2022-12-23
编辑:Stephen23 2022-12-23
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by