2
votes

I have a problem with dates when I import a time series from excel to matlab using the 'xlsread' command. For example, in my excel spreadsheet a date/time as of 09.12.13 09:03 (December 9th, 2013) translates in number equal to 41617.37708333330. When I import it to matlab, in serial date number type it remains the same 41617.37708333330 but when I convert it to a date string or date vector type (using the command detester or respectively datevec) it translates in

10-Dec-0113 09:03:00 or [113 12 10 9 3 0]

i.e. one day after (10 instead of 9) and a different year (0113 instead of 2013).

Does anybody know why it is the case and how to solve it?

thank you in advance for any help.

John

1

1 Answers

4
votes

Matlab uses a date-to-number convention where 1-jan-0000 is 1, and excel uses a convention where 1-jan-1900 is 1. So when you read in the excel date as a number, you have to convert it from one convention to the other.

If numDate is the value read from excel, and you want to make the string txtDate, try

txtDate=datestr(numDate+datenum('1-jan-1900')-1)