Date input from csv changing
    2 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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 件のコメント
採用された回答
  Cris LaPierre
    
      
 2025 年 3 月 25 日
        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);
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Dates and Time についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!