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 Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by