MATLAB: How to convert column datetime to datenum

datenumdatetimefor loopMATLAB

HI everyone,
I have a .csv file with a datetime column, in the format 'yyyy/m/d hh:mm:ss', for example: '2019/5/2 10:21:25'.
So, earlier dates in the month will be yyyy/m/d but later this will change to yyyy/mm/dd.
I want to convert these datetimes to datenum, as code I am using from a colleague which relies on datenum as an input.
I tried the following, where data.DateTime is a column in a table of such datetimes.
formatIn = 'yyyy/m/d HH:MM:SS';
datenumber=datenum(data.DateTime,formatIn)
However, I get the error "too many input arguments".
Thank you in advance for your help!
Louise

Best Answer

It is not clear from your example what class data has: a table or a non-scalar structure or .. ?
In any case, datetime objects do not need a format to be converted to serial date numbers:
DN = datenum(data.DateTime) % If data is a table or a scalar structure
DN = datenum([data.DateTime]) % If data is a non-scalar structure
As the documentation shows, the format argument is only used for date string inputs: