Change imported date into datetime format

1 visualización (últimos 30 días)
AA
AA el 23 de Ag. de 2020
Comentada: Star Strider el 23 de Ag. de 2020
Hi,
I have a cell array with many dates that were imported from an excel file.
Each cell array entry looks like this ie. 08/21/2020 (Aug).
I want to change the above format into a datetime format.

Respuesta aceptada

Star Strider
Star Strider el 23 de Ag. de 2020
Try this:
de = '08/21/2020 (Aug)';
DT = datetime(de, 'InputFormat','MM/dd/yyyy (MMM)')
producing (using the default Format):
DT =
datetime
21-Aug-2020
.
  1 comentario
Star Strider
Star Strider el 23 de Ag. de 2020
That Format only works with datetime (introduced in R2014b with significant updates in R2016b), that you apparently do not have access to.
To do the same with datenum and datestr, try this:
de = ['08/21/2020 (Aug)'; '09/21/2020 (Sep)']
DT = datenum(de, 'mm/dd/yyyy')
DS = datestr(DT)
producing:
DT =
738024
738055
DS =
2×11 char array
'21-Aug-2020'
'21-Sep-2020'
So, just ignore the short month designation string in parentheses.
I created a duplicate for September to be certain it would work with more than one value in the column vector. It appears to work well with them.
.

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.

Community Treasure Hunt

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

Start Hunting!

Translated by