datetime - can I fix wrongly encoded datetimes from Excel?

조회 수: 2 (최근 30일)
dormant
dormant 2025년 4월 9일
편집: Stephen23 2025년 4월 10일
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
Cris LaPierre
Cris LaPierre 2025년 4월 9일
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 2025년 4월 9일
편집: Stephen23 2025년 4월 10일
"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?"

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by