Convert SQL dates to MATLAB datenums
显示 更早的评论
I'm new to the database toolbox and cannot figure out how to convert SQL dates to MATLAB datenums. In the past, I've been able to do the following for converting Excel dates to MATLAB datenums:
[~, ~, raw, dateNums] = xlsread('path','Metrics','','',@convertSpreadsheetDates);
R = ~cellfun(@isequalwithequalnans,dateNums,raw) & cellfun('isclass',raw,'char');
raw(R) = dateNums(R);
I've tried doing something similar after connecting to a database and running a SQL script but got an error (below). Now that the variable raw is cell array containing my results. Only one column is a date column (the rest are numeric or binary). The variable R does indeed output what I'd expect (1 for date, 0 for number). But the function call to datenum results in an error pasted below the code.
R = cellfun('isclass', raw, 'char');
raw(R) = datenum(R, 'yyyy-mm-dd');
data = cell2mat(raw);
Error using datenum (line 178) DATENUM failed.
Error in DatabaseImport (line 23) raw® = datenum(R, 'yyyy-mm-dd');
Caused by: Error using datenum (line 106) The input to DATENUM was not an array of strings.
Does anyone know an easy way to convert SQL dates to MATLAB dates?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!