Remove time from datetime

36 visualizaciones (últimos 30 días)
vidit kedia
vidit kedia el 21 de En. de 2021
Comentada: vidit kedia el 21 de En. de 2021
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.

Respuesta aceptada

Steven Lord
Steven Lord el 21 de En. de 2021
Editada: Steven Lord el 21 de En. de 2021
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 comentario
vidit kedia
vidit kedia el 21 de En. de 2021
Thanks a lot Steven. This works perfectly.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by