Removing time from datetime
    80 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi,
I have a datetime array in the following format  i.e.  31-Dec-2019 08:00:00. I just want to remove the time component from the datetime so that I get  31-Dec-2019. Any ideas
0 commentaires
Réponse acceptée
  Steven Lord
    
      
 le 23 Août 2020
        
      Modifié(e) : Steven Lord
    
      
 le 23 Août 2020
  
      If you want to change how it is displayed, change the Format property.
>> dt = datetime('now')
dt = 
  datetime
   23-Aug-2020 15:43:06
>> dt.Format = 'dd-MMM-yyyy'
dt = 
  datetime
   23-Aug-2020
If you want to change what's stored and used for calculation, dateshift the datetime to the start of the day.
>> dt2 = dateshift(dt, 'start', 'day');
>> dt - dt2
ans = 
  duration
   15:43:06
0 commentaires
Plus de réponses (1)
  Star Strider
      
      
 le 23 Août 2020
        Try this: 
dt = '31-Dec-2019 08:00:00';
Out = datetime(dt, 'InputFormat','dd-MMM-yyyy HH:mm:ss', 'Format','dd-MMM-yyyy')
producing: 
Out = 
  datetime
   31-Dec-2019
.
0 commentaires
Voir également
Catégories
				En savoir plus sur Dates and Time dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


