Error using datetime Input data must be one numeric matrix when converting from a different date/time representation.
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    tyler seudath
 il 4 Mar 2023
  
    
    
    
    
    Commentato: Peter Perkins
    
 il 13 Mar 2023
            Hi Everyone, 
I am trying to export time data from excel and to but in format HH:mm and remove the date and year but I am getting the error "Error using datetime Input data must be one numeric matrix when converting from a different date/time representation."
The code is attached:
[file,path] = uigetfile('*.xlsx','Select a File'); %Opening modal dialog box to get the excel file (xlsx ensures that only excel files are shown)
            fpath=[path,file];  % File path of excel file
            app.FilePathEditField.Value=fpath; % Assigning the file path to the edit field area
            app.H = readtable(app.FilePathEditField.Value);
            app.H.Time_24HourClock_= datetime(app.H.Time_24HourClock_,'ConvertFrom','excel','Format','HH:mm');% Here has the error
            app.UITable.Data =app.H; 
0 Commenti
Risposta accettata
  Cris LaPierre
    
      
 il 4 Mar 2023
        We really need to know more about your variable values to say for certain, but I suspect what is happening is that readtable has already read the Time_24HourClock_ data as a datetime. So the error is likely caused by passing a datetime variable as input to datetime.
D = datetime('now');
datetime(D,'ConvertFrom','excel','Format','HH:mm')
To change the display format of your table variable Time_24HourClock_, try the following:
app.H.Time_24HourClock_.Format = 'HH:mm';
2 Commenti
  Peter Perkins
    
 il 13 Mar 2023
				In addition:
Changing the display format does nothing to the actual datetime values in app.H.Time_24HourClock_. They are still dates and times. If your goal is to treat them as times-of-day, you may well be better off calling timeofday on that table variable rather than changing its display format. Hard to tell, though.
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Spreadsheets in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


