Borrar filtros
Borrar filtros

Parse variable in a table

2 visualizaciones (últimos 30 días)
Inna Pelloso
Inna Pelloso el 8 de Ag. de 2023
Comentada: Star Strider el 8 de Ag. de 2023
Hi,
I have a variable in a table, timestamp, in the following format:
2023-02-24 13:00:00
How can I parse this variable into two new variables, date (2023-02-24) and time (13:00:00)?
Any help would be appreciated!
IP

Respuesta aceptada

Star Strider
Star Strider el 8 de Ag. de 2023
Editada: Star Strider el 8 de Ag. de 2023
Several options, depending on what you want —
timestamp = '2023-02-24 13:00:00'
timestamp = '2023-02-24 13:00:00'
DT = datetime(timestamp)
DT = datetime
24-Feb-2023 13:00:00
Date = DT;
Time = DT;
Date.Format = 'yyyy-MM-dd'
Date = datetime
2023-02-24
Time.Format = 'HH:mm:ss'
Time = datetime
13:00:00
Date = extractBefore(timestamp, ' ')
Date = '2023-02-24'
Time = extractAfter(timestamp, ' ')
Time = '13:00:00'
DateTime = strsplit(timestamp, ' ')
DateTime = 1×2 cell array
{'2023-02-24'} {'13:00:00'}
EDIT — Added strsplit call.
.
  2 comentarios
Inna Pelloso
Inna Pelloso el 8 de Ag. de 2023
Thank you!
Star Strider
Star Strider el 8 de Ag. de 2023
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by