A problem with the date structure

Dear all,
I load some data from an excel file and I obtain D={
'dates'
[40521]
[40461]
[40370]
[40310]
[40575]
'30/01/11'
'27/02/11'
'27/03/11'
'24/04/11'
'22/05/11'
'19/06/11'
'17/07/11'
'14/08/11'
[40856]
[40796]
[40705]
};
I know that is has to do with the setting of excel and that I should format the dates.
Can I correct this problem within Matlab so as to have only this format '17/07/11' and not date numbers?
thanks

 채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 29일

0 개 추천

idx_to_change = cellfun(@isnumeric, D);
dateshift = 695422; %1904 date system; 693960 for 1900 date system
D(idx_to_change) = cellstr( datestr( [D{idx_to_change}] + dateshift ) );

댓글 수: 4

salva
salva 2012년 7월 29일
편집: salva 2012년 7월 29일
thank you walter. Yet I obtain '12-Jun-2011' instead of 12/9/2011 and also these dates that are created are wrong.
any suggestions?
thanks
salva
salva 2012년 7월 29일
편집: salva 2012년 7월 29일
I tried
idx_to_change = cellfun(@isnumeric, D);
dateshift =693960; %1904 date system; 693960 for 1900 date system
zz = cellstr( datestr( [D{idx_to_change}] + dateshift ) );
newdates=datestr(zz, 'mm/dd/yy')
D(idx_to_change)=cellstr(newdates);
and it worked.
For some reason when I issue the command
newdates=datestr(zz, 'mm/dd/yy')
I obtain the output day/month/year which I should not expect as I have specified 'mm/dd/yy'
Why is this the case?
Could you please verify the correctness of the above code?
thanks
newdates = cellstr( datestr( [D{idx_to_change}] + dateshift, 'mm/dd/yy' ) );
salva
salva 2012년 7월 29일
thank you:)

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

추가 답변 (0개)

카테고리

도움말 센터 및 File 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