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

 채택된 답변

Steven Lord
Steven Lord 2020년 8월 23일
편집: Steven Lord 2020년 8월 23일

5 개 추천

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

추가 답변 (1개)

Star Strider
Star Strider 2020년 8월 23일

4 개 추천

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
.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

AA
2020년 8월 23일

편집:

2020년 8월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by