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 Comment

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

Sign in to comment.

 Accepted Answer

dpb
dpb on 26 Jun 2026 at 16:23
Edited: dpb on 27 Jun 2026 at 12:23
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

More Answers (0)

Categories

Products

Release

R2025a

Tags

Asked:

on 26 Jun 2026 at 16:04

Moved:

on 27 Jun 2026 at 12:24

Community Treasure Hunt

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

Start Hunting!