how to subtract the datetimes

10 ビュー (過去 30 日間)
MakM
MakM 2022 年 12 月 23 日
編集済み: Stephen23 2022 年 12 月 23 日
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
  1 件のコメント
MakM
MakM 2022 年 12 月 23 日
Thanks Stephan for the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by