datetime format with T time demarcation

I have data that I've read in with datetime format that includes a T such as:
>> ais_data.BaseDateTime(3)
ans =
datetime
2023-08-01T11:07:56
If I change the value, how do I format the answer. For example, I would like to increment the minute, like such 2023-08-01T11:08:56
However, this results in the following error
>> datetime(2023-08-01T11:08:56)
datetime(2023-08-01T11:08:56)
Error: Unexpected 'T11'. Check for missing multiplication operator.
How do make a datetime number like the one I'm seeing in the example at the top?

1 件のコメント

Stephen23
Stephen23 2026 年 6 月 26 日 16:22
移動済み: Stephen23 2026 年 6 月 27 日 12:24
dt1 = datetime(2023,8,1,11,07,56, "Format","yyyy-MM-dd'T'HH:mm:ss")
dt1 = datetime
2023-08-01T11:07:56
dt2 = dt1 + minutes(1)
dt2 = datetime
2023-08-01T11:08:56

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

 採用された回答

dpb
dpb 2026 年 6 月 26 日 16:23
編集済み: dpb 2026 年 6 月 27 日 12:23

0 投票

You're trying to convert a string representation so it has to be a string variable of some type... (+)
datetime('2023-08-01T11:08:56')
ans = datetime
01-Aug-2023 11:08:56
If you have a datetime variable already, then increment it instead of trying to convert..
ais_data.BaseDateTime=datetime('2023-08-01T11:07:56')
ais_data = struct with fields:
BaseDateTime: 01-Aug-2023 11:07:56
newDateTime=ais_data.BaseDateTime+minutes(1)
newDateTime = datetime
01-Aug-2023 11:08:56
(+) If you have a value as datetime, to convert the string representation would be
ais_data.BaseDateTime.Format='yyyy-MM-dd''T''HH:mm:ss'; % default format doesn't include T
date_str=string(ais_data.BaseDateTime)
date_str = "2023-08-01T11:07:56"
datetime(date_str)
ans = datetime
01-Aug-2023 11:07:56

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

リリース

R2025a

タグ

質問済み:

2026 年 6 月 26 日 16:04

移動済み:

2026 年 6 月 27 日 12:24

Community Treasure Hunt

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

Start Hunting!

Translated by