datetime - can I fix wrongly encoded datetimes from Excel?

6 views (last 30 days)
I have to read an Excel spreadsheet into MATLAB. The spreadsheet is not mine.
Someone, at some point in updating this spreadsheet, switched from UK-format dates (DD/MM/YYYY) to US format dates (MM/DD/YYYY). Changing the date format in Excel doesn't change anything because the dates are stored as serial numbers.
MATLAB has difficulty reading these dates using readtable. Some of them are stored as NaT.
Is there any way I can read the spreadsheet into MATLAB, then fix the dates? I know which rows in the table have the bad dates in them.
  2 Comments
Cris LaPierre
Cris LaPierre on 9 Apr 2025
Most likely yes, but please share a sample spreadhseet for us to test with.
It will require deconstructing then reconstructing the dates, so it would be helpful to have a column in the data set showing what the dates should be for comparison.
Stephen23
Stephen23 on 9 Apr 2025
Edited: Stephen23 on 10 Apr 2025
"Changing the date format in Excel doesn't change anything because the dates are stored as serial numbers. MATLAB has difficulty reading these dates using readtable."
READTABLE also reads the serial date numbers, so the date format used by Excel is totally irrelevant. If the cell actually contains an excel serial date number then READTABLE will have no problems reading it.
Upload the file, most likely the dates are not what you think they are.
"Is there any way I can read the spreadsheet into MATLAB, then fix the dates?"

Sign in to comment.

Answers (0)

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!