importdata not reading time stamp from excel sheet accurately

2 visualizaciones (últimos 30 días)
I have been using importdata to read an excel sheet with time stamps. The time stamp on excel sheet is 1/1/2015 12:20:18 AM. When importdata is used, this time stamp gets converted to [42005.014097222]. I tried using datestr([42005.014097222],31) command and this is being converted to '0115-01-02 00:20:18'; but it has to be 2015-01-01 00:20:18'. How can this be fixed? Thank you!
Here is the program:
[filename, pathname] = uigetfile({'*.*'},'Choose the input file');
delimiterIn = ',';
headerlinesIn = 0;
A = importdata([pathname filename],delimiterIn,headerlinesIn); %this is a long array of time stamps, just citing one in the example above.
start_time=A(:,1); %start_time(1)=[42005.014097222]; but the 1st element in the excel sheet is 1/1/2015 12:20:18 AM
stop_time=A(:,2);
[y1,m1,d1,h1,m1,s1]=datevec(datestr(start_time,31)); %the result here gives me y1=115 and d1=2; but the right result should be y1=2015 and d1=1.
[y2,m2,d2,h2,m2,s2]=datevec(datestr(stop_time,31));

Respuesta aceptada

Ajay Kumar
Ajay Kumar el 28 de Sept. de 2019
Editada: Ajay Kumar el 29 de Sept. de 2019
The default date for excel is 1899/12/30_00:00:00. So you have to add this to the date number to get the correct date.
Try this
t1 = datenum('1899/12/30_00:00:00','yyyy/mm/dd_HH:MM:SS');
datestr(t1+42005.014097222)
Please accept the answer if you got what you need. Thanks :)
  5 comentarios
Danya Pradeep Kumar
Danya Pradeep Kumar el 29 de Sept. de 2019
Thank you, Stephen! That makes sense.
Ajay Kumar
Ajay Kumar el 29 de Sept. de 2019
Corrected. Thanks for the info Stephen :)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by