Creating a vector of datetimes with increments of 15 minutes

조회 수: 40 (최근 30일)
Cmullica
Cmullica 2020년 8월 7일
댓글: Star Strider 2020년 8월 7일
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?

채택된 답변

Star Strider
Star Strider 2020년 8월 7일
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
Cmullica
Cmullica 2020년 8월 7일
Thank you so much, you just made my day.
Star Strider
Star Strider 2020년 8월 7일
As always, my pleasure!
I very much appreciate your compliment!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by