MATLAB: I have a CSV file with date and time values I want to import and convert to datetime

csvdatetime

The import tool will not convert this to Datetime and I have tried many different options all of which will not allow me to convert the dates in this CSV file to datetime. Example of the format of the dates in the CSV file: {'1/1/2015 1:00:00 AM'} The format of the data is Month/Day/Year Hour:Min:Second AM or PM There are no "0"s infront of any of the month or day values. I have tried MM/DD/YYYY and many different versions of this format
Code that does not work:
DateStrings = importfile(:,'DateTime');
t = datetime(DateStrings,'InputFormat','M/d/y h:MM:SS a');
The clock values are a 12 hour clock as they start at just a date value and then the next value has the hour data and the AM/PM. Any help would be greatly appreciated!

Best Answer

Use
t = datetime(DateStrings,'InputFormat','M/d/y h:mm:ss a');
instead. 'MM' --> Months and 'SS' --> fractional seconds fields. See <datetime-properties Format>