cell to string to date time

I am importing a time from a .txt file. The import was auto-generated by matlab. The timestamp array is in this form: '2015-08-07 13:12:00' The variable is a 100x1 cell...I am not sure how to get the cell to a usable date time. Thank you.
...I can also import from the auto-generated import, however the import format does not match any of the available formats.

Answers (2)

datenum(TheCell)
to return the older serial datenum objects.
datetime(TheCell)
to return the newer datetime objects.
Samantha, it sounds like you have code that you generated using the Import Tool. When you import a text file using the IT, you can specify that a particular column is datetime strings, and even specify a custom format for the strings. I cooked up a file with one column of numbers and one column of datetime strings, and the code I generated contains a line like
formatSpec = '%f%{yyyy-MM-dd HH:mm:ss}D%[^\n\r]';
That script/function will import that column as a datetime array. It's not clear if that's what you're looking to do.

Categories

Asked:

on 16 Aug 2015

Answered:

on 18 Aug 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!