How do I obtain the end of month dates for a time interval?

5 ビュー (過去 30 日間)
joseph Frank
joseph Frank 2011 年 7 月 3 日
if i have two dates that constitute a time interval such as : 726864 and 734169 is it possible to compute the end of month dates for the whole time interval?

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 7 月 3 日
d = [726864,734169]
dv = datevec(d(1):d(2));
d2 = unique(dv(:,1:2),'rows');
dm = eomday(d2(:,1), d2(:,2))

その他の回答 (1 件)

the cyclist
the cyclist 2011 年 7 月 3 日
I think the Financial Toolbox has functions that make things like this easier. Also, have you looked at the File Exchange?
Absent that toolbox, one way to do this would be to extract the year/month of your two dates using the datevec() command, which should make it easy to find all the interim months. Then make a vector with year-month-date of the first of each month, which is easier than finding the last date of each month (which can be 28,29,30, or 31!). Then, subtract a day to get the last datenum of the previous month.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by