Datetime, parsing problem

조회 수: 5 (최근 30일)
mehra
mehra 2019년 6월 7일
답변: mehra 2019년 6월 10일
I am using Datetime function for a set of 104 excel data, but in some of the data I face with parsing error, although all the files have the same format and the excel cell that will be used in the datetime also is the same in all the data sets but datetime give error that it can not parse the
why this happens and how I can Solve it?
  댓글 수: 6
mehra
mehra 2019년 6월 10일
편집: mehra 2019년 6월 10일
I send some of the related lines, please let me know if somethıng else is needed
The Error I get (for almost Every other xlsx fıle ) is this one:
Error using datetime (line 593)
Unable to parse date/time string '09:55:46.663917949583 29.10.2018' using the format 'HH:mm:ss.SS dd.MM.yyyy'.
Error in data_processing_unsteady_2D_90sec_xz (line 79)
recdate=datetime(dummy2,'InputFormat','HH:mm:ss.SS dd.MM.yyyy');
I read my excel fıles by :
WL_data_list_xz1=dir('xz/*.xlsx');
The lines related to Error:
WL_datafilename=strcat('xz/',WL_data_list_xz1(n1).name);
[WL_time,dummy1,dummy2]=xlsread(WL_datafilename,1,'B8');
recdate=datetime(dummy2,'InputFormat','HH:mm:ss.SS dd.MM.yyyy');
Walter Roberson
Walter Roberson 2019년 6월 10일
In datatime parsing, you cannot use SS to indicate that you want 12 digits of fractions of a second. You would need to use 12 S's to indicate 12 digits of fractions of a second. However, MATLAB only permits 9 S's, so your 09:55:46.663917949583 cannot be processed. MATLAB cannot store seconds that precise. You will need to process the times to reduce it to 9 digits.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 10일
편집: Walter Roberson 2019년 6월 10일
dummy3 = regexprep(dummy2, '\.(\d{9})\d{3} ', '.$1 '); %remove last 3 digits
recdate = datetime(dummy3, 'InputFormat', 'HH:mm:ss.SSSSSSSSS dd.MM.yyyy');

추가 답변 (2개)

mehra
mehra 2019년 6월 10일
Thank you very much, but here some of my fıles can be processed however in all of them there are 12 digits for seconds

mehra
mehra 2019년 6월 10일
Thank you very much

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by