Problem with importing Date & time from Excel

2 次查看(过去 30 天)
Excel datas are these
2015-09-06 10:00:04 AM
2015-09-06 9:58:29 AM
date and time which in one line are in one cell. So I mean [2015-09-06 10:00] <- this is one cell in excel
I tried to import these date and time from excel to matlab by using xlsread fuction.
but I found that the form of data& time were changed like these
'2015-09-06 오전 10:00:04'
'2015-09-06 오전 9:58:29'
1. the date form is slitely changed [AM -> 오전]
I think matlab recognize the data form but it change in to Korean word.
How can I import excel date & time without changing it's form
2. and I tried to using datavec fucntion. but this error come out
Caused by:
[Error using datevec (line 247)
Too many time fields in 2015-09-06 오전 10:00:04.]
3. after all I do these to calculate gap between time and time
How can I do these?

回答(2 个)

Walter Roberson
Walter Roberson 2015-9-8
It looks to me as if you are using R2014b or later and have configured the dates to be converted to datetime objects. If so then add the line
datetime.setDefaultFormats('default','yyyy-MM-dd h:mm:ss a')
and see if that helps. If I am correct then it is the display of the times that is being affected, not what is stored
If I am correct about it being datetime objects, then to find the difference between two times, just subtract them. You can assign a display format to the result:
timegap = time2 - time1;
timegap.Format = 'hh:mm:ss';
  1 个评论
SANGJUN PARK
SANGJUN PARK 2015-9-9
I just typed below fuction as you said
datetime.setDefaultFormats('default','yyyy-MM-dd h:mm:ss a'
but there are also problem like this
Undefined variable "datetime" or class "datetime.setDefaultFormats".
I still jamed in this line. What should I do?

请先登录,再进行评论。


Peter Perkins
Peter Perkins 2015-9-9
Sangjun, it sounds like you're using a version of MATLAB prior to R2014b, so Walter's suggestion won't work.
I'm assuming your (Windows) machine is set to Korean/Korea. Excel does some funny things when localizing dates/times, and although you see things like 2015-09-06 10:00:04 AM when you view the spreadsheet, Excel actually returns things like 2015-09-06 오전 10:00:04 to MATLAB for the contents of those cells. (Strangely, when I created a spreadsheet and edited a date/time cell, Excel temporarily displayed the Korean characters for AM/PM, but then switched back when I was done editing.)
So: I think the simplest thing for you to do is to change the format of the cells in Excel to not use the AM/PM token.

Community Treasure Hunt

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

Start Hunting!

Translated by