Asked by saharsahar
on 12 Jun 2013

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 !

*No products are associated with this question.*

Answer by per isakson
on 12 Jun 2013

Edited by per isakson
on 12 Jun 2013

Accepted answer

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.

Answer by saharsahar
on 12 Jun 2013

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!

Show 1 older comment

saharsahar
on 15 Jun 2013

in MATLAB 2009 , it is as follows:

which x2mdate

C:\Program Files\MATLAB\R2009b\toolbox\finance\calendar\x2mdate.m

However in MATLAB 2012b it is:

>> which x2mdate

'x2mdate' not found.

Regardless of x2mdate, is there anyway to match the dates by Excel and MATLAB the same?

Thanks

per isakson
on 15 Jun 2013

There is a contribution in the File Exchange, xlsdate, which promises to help.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments