필터 지우기
필터 지우기

Adding month values to datetime function

조회 수: 35 (최근 30일)
Jay
Jay 2016년 5월 26일
댓글: Andrei Bobrov 2016년 5월 27일
If I have a datetime value of today, can I add 3 or 6 months to that value without splitting the date into 3 separate arrays (dd, MM, yyyy)?

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2016년 5월 26일
편집: Andrei Bobrov 2016년 5월 26일
out = datetime('now') + calmonths([3,6])
before R2014b
out = addtodate(now ,[3,6],'month')
  댓글 수: 5
Andrei Bobrov
Andrei Bobrov 2016년 5월 27일
Yes, if your date(ObsDate) - scalar serial date number (read doc about addtodate)
Andrei Bobrov
Andrei Bobrov 2016년 5월 27일
if ObsDate and Q - array example:
ObsDate = [2016 5 29;2016 6 14];
Q = [3 4 15];
D = datenum(ObsDate);
a = bsxfun(@(x,y)addtodate(x,y,'month'),D(:),Q(:)');
out = arrayfun(@datestr,a,'un',0)

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


Jay
Jay 2016년 5월 27일
편집: Jay 2016년 5월 27일
Never mind I figured out what was wrong.
CalWin = datenum(ObsDate)
CalWin = addtodate(CalWin, 3, 'month')
datestr(CalWin)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by