Karol B
Karol B

Reputation: 73

How to create modified date time in Matlab?

I need to create a list of datetime as presented in the attached Figure in Matlab, but I am not getting it.. so far I have done:

t1 = datetime(2016, 4, 1, 0, 0, 0);
t2 = datetime(2018, 12, 31, 23, 45, 0);
tinc = 15; 
t = t1:minutes(tinc):t2;

But it gives me "01-Apr-2016 00:00:00"

Instead, I need:

2016-04-01 00:00:00 2016-04-01 00:15:00 ... 2018-12-31 23:45:00

Can someone explain to me how can I do it?

(The +01:00 is for daytime savings days that I can append later I guess).

enter image description here

Upvotes: 1

Views: 45

Answers (1)

Paolo
Paolo

Reputation: 26211

Use the Format option with the desired specifier:

>> t= datetime(t1:minutes(tinc):t2,'Format','yyyy-MM-dd HH:mm:SS');
>> t(1:2)

ans = 

  1×2 datetime array

   2016-04-01 00:00:00   2016-04-01 00:15:00

You can find more information on the Display Format for datetime here.

Upvotes: 2

Related Questions