Creating a vector of datetimes with increments of 15 minutes

40 visualizaciones (últimos 30 días)
Hi all, currently trying to create a datetime vector with the form of 'yyyy-mm-dd HH:mm:ss' ranging from 2020-06-30 23:45:00 to 2015-01-01 00:00:00
in other words, elements should read as follows:
element 1 = 2020-06-30 23:45:00
element 2 = 2020-06-30 23:30:00
and so on.
I've tried converting to datenum for serial numbers and thought I could figure out the increment for 15 minutes and build from the first serialized number to the last such that timevec = t1:step:t_final with step = datenum(t1-t2) type of logic... didn't work out in my favor though.
Any suggestions?

Respuesta aceptada

Star Strider
Star Strider el 7 de Ag. de 2020
Try this:
Timestamp = (datetime('2020-06-30 23:45:00') : -minutes(15) : datetime('2015-01-01 00:00:00')).';
Timestamp.Format = 'yyyy-MM-dd HH:mm:ss';
producing:
First5_Last5 = [Timestamp(1:5); Timestamp(end-4:end)]
First5_Last5 =
10×1 datetime array
2020-06-30 23:45:00
2020-06-30 23:30:00
2020-06-30 23:15:00
2020-06-30 23:00:00
2020-06-30 22:45:00
2015-01-01 01:00:00
2015-01-01 00:45:00
2015-01-01 00:30:00
2015-01-01 00:15:00
2015-01-01 00:00:00
.
  2 comentarios
Cmullica
Cmullica el 7 de Ag. de 2020
Thank you so much, you just made my day.
Star Strider
Star Strider el 7 de Ag. de 2020
As always, my pleasure!
I very much appreciate your compliment!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown 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