Creating a vector of datetimes with increments of 15 minutes

40 views (last 30 days)
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?

Accepted Answer

Star Strider
Star Strider on 7 Aug 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
.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!