MATLAB: Convert “Jul_26_20​16__11-26-​37_AM” to Date Vector

date stringdate vector

I want to convert time string in the format of "Jul_26_2016__11-26-37_AM" to Date Vector. But I am not sure how to deal with the AM PM thing. In my data there are both AM and PM present.

Best Answer

According to the datevec documentation (did you read it ?) you can simply put either AM or PM in the token position to read the AM/PM info:
>> datevec('Jul_26_2016__11-26-37_AM','mmm_dd_yyyy__HH-MM-SS_AM') % AM
ans =
2016 7 26 11 26 37
>> datevec('Jul_26_2016__11-26-37_PM','mmm_dd_yyyy__HH-MM-SS_AM') % PM
ans =
2016 7 26 23 26 37