How do I specify a datetime format when reading a .csv/Excel file?

18 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
You can use 'setvaropts' to change the format of datetime variables. For example:
opts = detectImportOptions('example.csv');
opts = opts.setvaropts('myVariable','InputFormat','M/d/yyyy','DateTimeFormat','dd-MMM-yyyy');
t = readtable('example.csv',opts)
% 'example.csv' contains the column:
% myVariable
% 1/31/2020
'InputFormat' tells 'readtable' how to interpret the values in the file, while 'DateTimeFormat' tells MATLAB how to display the datetimes once they are in MATLAB.
For more information, refer to the "Import Date and Time Data" section on the following documentation page:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by