MATLAB: Removing time from datetime

removing datetime format

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

Best Answer

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