trouble using datetime format in textscan

this datetime format works
datetime('2021-05-01 06:10:00','inputFormat','yyyy-MM-dd HH:mm:ss')
so why won't
>> textscan('2021-05-01 06:10:00','%{yyyy-MM-dd HH:mm:ss}D')
Error using textscan
Unable to read the DATETIME data with the format 'yyyy-MM-dd HH:mm:ss'. If the data is not a time, use %q to get text data.
Thanks.

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 7월 20일
The problem is because textscan uses white space as the default delimiter. Specify your delimiter or remove the space between date and time.
d1 = textscan('2021-05-01 06:10:00','%{yyyy-MM-dd hh:mm:ss}D','Delimiter','\t')
d1 = 1×1 cell array
{[2021-05-01 06:10:00]}
d2 = textscan('2021-05-0106:10:00','%{yyyy-MM-ddhh:mm:ss}D');
d2{1}.Format = 'yyyy-MM-dd hh:mm:ss'
d2 = 1×1 cell array
{[2021-05-01 06:10:00]}

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 20일

댓글:

2021년 7월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by