year command does not work properly

3 views (last 30 days)
Sina Kian
Sina Kian on 12 Dec 2019
Answered: Walter Roberson on 12 Dec 2019
I made an excel file which its first column is in date format including time and date. I insert it in matlab, the problem is that my years start from 2012 till 2015 but year function of matlab read it as 112 till 116. it makes me a lot of problem.
who knows what is the problem? how can I fix the problem of coincidence of matlab and excel? it would be a big help.
thanks for your time.
all the best
2.JPG
this is an example: Column 1 is the date which is not proper in excel but proper in matlab. (second row is the same date but in number format)
column 2 is the date that is true in excel but not proper in matlab.
first date' year is 1989, second one is 2012.
now in following photos I'll show how matlab reads them.
4.JPG
as you see the one which was 2012 is shown here as 112
and the one which was 3888 is shown here 1989.
Now I am working with the ones that are proper in excel. how can I use them in matlab properly
  3 Comments
Walter Roberson
Walter Roberson on 12 Dec 2019
txt files are never excel files. At best txt files might be in csv format but csv that have / cannot be load()'d.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 12 Dec 2019
It looks to me as if you are trying to read an excel numeric date. Excel uses Jan 1 1990 as its time base.
If you have an excel file with Excel formatted date then readtable() will automatically convert it for you.
If for some reason you need to work with Excel numeric dates then use datetime with 'convertfrom' 'Excel'

Tags

Community Treasure Hunt

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

Start Hunting!