Problem reading excel dates with readtable on different computers
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have made a script on my computer to read dates from an excel file, dates are in the format 'dd/mm/yyyy hh:mm' in the excel file, and it works perfectly. But then i tried the same script in another computer which has a different language settings and now readtable is reading the excel dates as 'mm/dd/yyyy hh:mm' which is a problem for the later parts of the script. To make things worst i tried this same script in a third computer which is in the same local language as the first one but readtable reads the dates as 'dd.mm.yyyy hh:mm' which is also a problem because i have a datenum command right after and it fails cause the format is different.
So my question is if theres a way to read the excel dates always on the format 'dd/mm/yyyy hh:mm' even if i run the script on different computers with different languages and different punctuations? So i dont have to change the datenum command every time i run the script on a new computer.
Thanks
0 个评论
回答(1 个)
darova
2020-4-10
What about this smart approach?
mystr = '24/04/2020 11:12';
form = {'dd/mm/yyyy HH:MM'
'mm/dd/yyyy HH:MM'
'dd.mm.yyyy HH:MM'};
for i = 1:length(form)
try
datenum(mystr,form{i})
catch exc
sprintf('form %d is wrong',i)
% rethrow(exc)
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!