using readtable to convert columns containing dates to datetime

2 visualizaciones (últimos 30 días)
Mailinh Nguyen
Mailinh Nguyen el 4 de Nov. de 2020
Respondida: Akira Agata el 4 de Nov. de 2020
I need to convert columns containing dates in the xlsx file to datetime format using readtable()
This is what have so far, but there is an error.
T = readtable('US_Presidents.xlsx'); %Create a table by reading from a file.
datetime(US_Presidents.BirthDate,'InputFormat', 'yyyy-MM-dd');

Respuestas (1)

Akira Agata
Akira Agata el 4 de Nov. de 2020
Like this?
T = readtable('US_Presidents.xlsx','PreserveVariableNames',true);
T.("Birth Date") = datetime(T.("Birth Date"));
T.("Death Date") = datetime(T.("Death Date"));
T.("Date took office") = datetime(T.("Date took office"));
T.("Date left Office") = datetime(T.("Date left Office"));

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by