Reputation: 145
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
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