Adding month values to datetime function
古いコメントを表示
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
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
2016 年 5 月 27 日
use now instead of 'now'
CalWin = addtodate(now, 3, 'month')
For Quantity in vector with arrayfun
out = arrayfun(@(x)addtodate(now,x,'month'),[3,6])
Andrei Bobrov
2016 年 5 月 27 日
Yes, if your date(ObsDate) - scalar serial date number (read doc about addtodate)
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)
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
