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 comentario

Stephen23
Stephen23 hace alrededor de 22 horas
Movida: Stephen23 hace alrededor de 2 horas
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

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb hace alrededor de 22 horas
Editada: dpb hace alrededor de 2 horas
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

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Etiquetas

Preguntada:

el 26 de Jun. de 2026 a las 16:04

Movida:

el 27 de Jun. de 2026 a las 12:24

Community Treasure Hunt

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

Start Hunting!

Translated by