how to have datetime for specific range?

Hi,
I want to have a datetime, monthly from 1982 to 2015, like this:
1/1/1982
2/1/1982
3/1/1982
...
12/31/2015
how to have it?

 Respuesta aceptada

Star Strider
Star Strider el 19 de Dic. de 2019
Try this:
dt1 = datetime([1982 01 01]);
dt2 = datetime([2015 12 31]);
dt_vec = dt1 : calmonths(1) : dt2;
FirstFive = dt_vec(1:5) % Display Results (Delete Later)
producing:
FirstFive =
1×5 datetime array
01-Jan-1982 01-Feb-1982 01-Mar-1982 01-Apr-1982 01-May-1982

3 comentarios

BN
BN el 19 de Dic. de 2019
oh, thanks greatly appreciated. is there any way to have this in 1/1/1982 format? I mean I don't want to have 1-Jan-1982 but I want 1/1/1982, furthermore, I would like to have all of them in the on column under each other (408*1)
thank you very much
dt1 = datetime([1982 01 01],'format','MM/dd/yyyy');
dt2 = datetime([2015 12 31],'format','MM/dd/yyyy');
dt_vec = dt1 : calmonths(1) : dt2;
FirstFive = dt_vec(1:5)
My pleasure.
Easily done:
dt1 = datetime([1982 01 01]);
dt2 = datetime([2015 12 31]);
dt_vec = (dt1 : calmonths(1) : dt2).';
dt_vec.Format = 'MM/dd/yyyy';
FirstFive = dt_vec(1:5) % Display Results (Delete Later)
producing:
FirstFive =
5×1 datetime array
01/01/1982
02/01/1982
03/01/1982
04/01/1982
05/01/1982

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

BN
el 19 de Dic. de 2019

Comentada:

el 19 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by