How do I specify a datetime format when reading a .csv/Excel file?
조회 수: 17 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 4월 1일
답변: MathWorks Support Team
2020년 4월 7일
I would like to change the datetime format of dates read in from .csv files. How do I do that?
채택된 답변
MathWorks Support Team
2020년 4월 1일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!