using readtable to convert columns containing dates to datetime

2 ビュー (過去 30 日間)
Mailinh Nguyen
Mailinh Nguyen 2020 年 11 月 4 日
回答済み: Akira Agata 2020 年 11 月 4 日
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');

回答 (1 件)

Akira Agata
Akira Agata 2020 年 11 月 4 日
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"));

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by