Date input from csv changing
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Victoria
el 25 de Mzo. de 2025
Comentada: Victoria
el 26 de Mzo. de 2025
Hi,
I'm mew to Matlab and i'm having an issue with date formats. I'm reading from a csv file, but the field of dates is going from 01/11/2012 in the csv to 01/11/0012 in matlab. I've played around with datetime, datestr and others but I can't figure out why it's reading as 0012 in the first place. The csv column is in the Date format and matlab gives me a warning saying it's being read as MM/dd/uuuu (see attached pic)
Is there a way I can get the readtable to interperate the date field as text? Then I can manually assign characters to dd/mm/yyyy?
Eventually, this will be the first of many csv's (all in the same format) being uploaded so I want to avoid changing the csv if possible.
Al the dates are actually the same for this file.
mytable = readtable(string(temp1_file));
dates = unique(mytable.Date)
dates =
datetime
01/11/0012
0 comentarios
Respuesta aceptada
Cris LaPierre
el 25 de Mzo. de 2025
The warning is telling you that the datetime format detected in the file is ambiguous. You can avoid this by specifying the format instead. You haven't shared what the data in your csv file looks like, but I'm guessing the dates are captured as 01/11/12
If so, try this.
opts = detectImportOptions(string(temp1_file));
opts = setvaropts(opts,'Date','InputFormat','dd/MM/yy');
mytable = readtable(string(temp1_file),opts);
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!