CodexBloom - Programming Q&A Platform

MATLAB 'readtable' scenarios to parse specific date format, causing NaT values

👀 Views: 465 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-16
matlab readtable datetime csv MATLAB

I need help solving I'm confused about I'm having trouble with the `readtable` function in MATLAB R2023b when trying to import a CSV file that contains dates in the format 'dd-MM-yyyy'... Instead of correctly parsing the dates, MATLAB is returning 'NaT' (Not-a-Time) for all entries. Here's a snippet of how I'm trying to read the table: ```matlab opts = detectImportOptions('data.csv'); opts = setvaropts(opts, 'DateColumn', 'Type', 'datetime', 'InputFormat', 'dd-MM-yyyy'); tableData = readtable('data.csv', opts); ``` Despite specifying the input format, the date parsing seems to be ignored. I've confirmed that the date column in the CSV indeed uses the 'dd-MM-yyyy' format, and there are no leading/trailing spaces or inconsistent formats. I also tried to manually specify the `Datetime` format directly in the `readtable` function: ```matlab tableData = readtable('data.csv', 'DatetimeType', 'datetime', 'InputFormat', 'dd-MM-yyyy'); ``` This still results in 'NaT' values. I also checked other possible options in `detectImportOptions`, but nothing seems to work. It seems like there may be an scenario with how MATLAB interprets this specific date format. Has anyone encountered this scenario or have any suggestions for getting `readtable` to correctly parse these date values? For context: I'm using Matlab on macOS. Any examples would be super helpful. I'm on CentOS using the latest version of Matlab. Any pointers in the right direction?