why "datestr" in matlab and date format cell in excell doesnt match?

조회 수: 1 (최근 30일)
Hi all, I have a date number , say 40667. When I am using datestr in matlab , it gives me 5 May, however I have the same number 40667 in excel sheet, when I use the date cell format(by clicking right->format cells-> date) , it gives me 4 May. However as far as I know the 4 May should be the right one. does anybody know why Matlab does not gives me the same result? and why there is mismatch between Matlab and Excel? Appreciated !

채택된 답변

per isakson
per isakson 2013년 6월 12일
편집: per isakson 2013년 6월 12일
Hint:
>> datestr( 40667, 'yyyy-mm-dd HH:MM:SS' )
ans =
0111-05-05 00:00:00
Start of time with Matlab is year 0 and with Excel 1900. See documentation.

추가 답변 (1개)

saharsahar
saharsahar 2013년 6월 12일
Thanks per isakson. I got that point and I searched and found "x2mdate" function which will solve the date conversion for me. But now I have problem using this function . Actually I am reading dates from Excel sheet using xlsread. the result will be cell or double : [num,txt,data]=xlsread(filepath); where num is double and data is cell. however the "x2mdate" gives me error for using cell or double formats:
here is my code:
[num,txt,data]=xlsread(filepath);
xx=num(1:end,19);
MATLABDate = x2mdate(xx,1);
and it gives me following error:
Undefined function 'x2mdate' for input arguments of type 'double'
Any help would be appreciated!
  댓글 수: 4
per isakson
per isakson 2013년 6월 15일
There is a contribution in the File Exchange, xlsdate, which promises to help.
saharsahar
saharsahar 2013년 6월 23일
Great ! Thank you very much . It works perfectly !

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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by