MATLAB: Date conversion in a number format

MATLAB

Hey guys
I have an excel file with the date format like this: '03/06/2014 11:39:04.324 PM' I want to convert this date format into (yyyymmddhhmmssSSS)20140306233904324. If the time is PM, then the hour should be in the format of 24 hours. Thanks in advance.

Best Answer

clc
str = '03/06/2014 11:39:04.324 PM';
[date,rem] = strtok(str,'/');
[month,rem]= strtok(rem,'/');
[year,rem]=strtok(rem,' ');
year = regexprep(year,'/','');
[hours,rem]=strtok(rem,':');
hours = regexprep(hours,' ','');
[mins,rem] = strtok(rem,':');
[sec,rem]=strtok(rem,'.');
sec = regexprep(sec,':','');
[msec,rem]= strtok(rem,' ');
[msec,y] = strtok(msec,'.');
if(strcmp(rem,' PM'))
hours = str2num(hours);
hours = hours+12;
hours = num2str(hours);
end
totaltime = [year date month hours mins sec msec]