MATLAB Answers

readtable is not reading the time 12:00:00 AM?

3 views (last 30 days)
Abhinav
Abhinav on 17 Feb 2020
Commented: Star Strider on 18 Feb 2020
I am using 'readtable' to read an excel file. The first column of the file contains date and time in 'mm/dd/yyyy HH:MM:SS PM' format. The probelm is the following:
The readtable skips the time if the entry is '5/7/2018 12:00:00 AM'. I want to read entire date-time string. is it possibel to do it using the readtable?
I am using the following code to invoke the readtable:
filename=fullfile(direc,station_name);
T=readtable(filename);
Note: the readtable is able to read other time-entries perfectly; the above time-entry is 1427th row in the file, including header.

  11 Comments

Show 8 older comments
Abhinav
Abhinav on 18 Feb 2020
Star Strider, I am using excel to visualize the data. I have no idea what is the issue with AM/PM designation. I will just go with ussual textscan, I think.
Abhinav
Abhinav on 18 Feb 2020
Star Strider: I just wanted to point out that when I convert the excel into a tab-separated text-file; the AM/PM designations go away and I can write my code.
Star Strider
Star Strider on 18 Feb 2020
Noted. Apparently the MATLAB application was adding the AM/PM designations, since they do not appear in the Excel file, at least that I can see.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 Feb 2020
Your input format specification should be 'MM/dd/yyyy hh:mm:ss a' to read that.
m is minutes not month
H is only for 24 hour clock
M is for month not minutes
S is for fractions of a second
PM is the wrong specifier for AM/PM

  3 Comments

Abhinav
Abhinav on 17 Feb 2020
Walter Robinson, the same problem still persists after changing the date format as per your sugggestion.
Walter Roberson
Walter Roberson on 17 Feb 2020
Please attach a sample file and your lines that invoke readtable()
Abhinav
Abhinav on 17 Feb 2020
I have attached the sample file now, along with the code lines.

Sign in to comment.