Alemex
Alemex

Reputation: 145

how to check the month of datenum matlab value?

I want to check the month and print the month value in the following code. please any advise?

formatOuttime = 'yyyy/mm/dd HH:MM:SS';
DateString = '2002/01/01 00:00:00';
datelooping=datenum(DateString,formatOuttime);
for i=1:100
    % do some stuff
    % check the month of the datelooping and print only the month value
    datelooping = datelooping+1;
end

Upvotes: 0

Views: 258

Answers (1)

Suever
Suever

Reputation: 65430

You can use datevec to split the date into multiple pieces

[year, month, day, hour, minute, second] = datevec(datelooping)

You could also pass your DateString directly to datevec

[year, month, day, hour, minute, second] = datevec(DateString)

Also, if you're on newer versions of MATLAB you can use a datetime object

dt = datetime(DateString, 'InputFormat', 'yyyy/MM/dd HH:mm:SS');

dt.month

Upvotes: 1

Related Questions