Importing dates from Excel using Matlab 2012a

Hello, I have been using xlsread with the 2012a release and I am very happy with it, except that I can't figure out how to get it to import the date properly. I have tried changing the excel column with the dates to a few different formats, but it always converts it to a number. I have also tried both the xlsx and xls formats for my input file. An example of my problem would be: importing 4/1/2012 gives the value 41000 in the 'num' and 'raw' arrays. Any help or workaround would be greatly appreciated, Ricardo

Answers (2)

Importing dates "as dates" is only directly handled on Windows when Excel is also installed. On Mac (even when Excel is installed) and Linux, or on Windows when Excel is not installed, you need to do this conversion yourself.
See When to Convert Dates from Excel Files in the documentation for MATLAB for information on how to do this.
Excel stores dates as numbers.
There is a MATLAB File Exchange contribution to convert Excel dates to serial datenum values, after which you can datestr() if you want to.

Asked:

on 20 Apr 2012

Community Treasure Hunt

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

Start Hunting!