datetime conversion from Excel to MATLAB wrong
Mostra commenti meno recenti
Problem:
when read excel into MATLAB, the date that is supposed to be 2012 gets translated into 2008
What I have:
an excel file, which only has one sheet.

What I did:
datetime.setDefaultFormats('default','yyyy/MM/dd hh:mm');
opts = detectImportOptions('MyExcelFile.xlsx');
RC_table = readtable('MyExcelFile.xlsx',opts);
What MATLAB gave me:

What else have I tried:
I tried using different date format in excel and correspondingly in MATLAB. It gives me the same problem.
I also tried in Excel, switch to the generic format. So the first date (2012/8/5 10:00) turns into 39664.4166666667. Then I say something like
t_datetime = datetime(39664.4166666667 + datenum(1900,01,01), 'ConvertFrom', 'datenum')
Somehow MATLAB thinks it is 2008/08/06 10:00 while excel thinks it is 2012/8/5 10:00
I also made sure I was reading the correct excel document.
Risposta accettata
Più risposte (1)
Walter Roberson
il 9 Set 2022
Modificato: Walter Roberson
il 9 Set 2022
datetime.setDefaultFormats('default','yyyy/MM/dd hh:mm');
hh is for 12 hour day. You need HH for 24 hour day.
1 Commento
Tongyao Pu
il 9 Set 2022
Categorie
Scopri di più su Data Import from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!