MATLAB: How to convert date to number

data acquisitionData Acquisition ToolboxMATLABstatisticsStatistics and Machine Learning Toolboxtoolbox

Hi, I have date as below: 2017/11/28 21:16:42, I want to convert it to number using datenum, but in matlab6p5 it give error that 2017 is too large as month. How can I do this? please help some one.

Best Answer

In MATLAB 6.5, that date format was not supported by datenum(), and that version of datenum() was too early to allow you to pass in a custom date specification.
I suggest that you use sscanf() to break apart the string into numeric pieces, and you can then pass those pieces in to datenum(). Your entries happen to be in the right order so you do not need to re-arrange the numeric parts:
S = '2017/11/28 21:16:42';
datenum( sscanf(S, '%d/%d/%d %d:%d:%d') )