Remove time from datetime

조회 수: 42 (최근 30일)
vidit kedia
vidit kedia 2021년 1월 21일
댓글: vidit kedia 2021년 1월 21일
I would like to remove the time from a datetime element, without using the .Format = 'dd-MMM-yyy', as this only chages the display format but the time component is still present in the element.

채택된 답변

Steven Lord
Steven Lord 2021년 1월 21일
편집: Steven Lord 2021년 1월 21일
Use timeofday to create a duration array containing the time since midnight for each of the datetime arrays.
rightNow = datetime('now')
rightNow = datetime
21-Jan-2021 15:35:16
timeSinceMidnight = timeofday(rightNow)
timeSinceMidnight = duration
15:35:16
And since I'm guessing you may be trying to "split" the datetime:
todaysDate1 = dateshift(rightNow, 'start', 'day') % or
todaysDate1 = datetime
21-Jan-2021
todaysDate2 = rightNow - timeSinceMidnight
todaysDate2 = datetime
21-Jan-2021
  댓글 수: 1
vidit kedia
vidit kedia 2021년 1월 21일
Thanks a lot Steven. This works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by