2011-02-01 54 views
0
int monthCount = GetMonthCount(comp.PaymentFrequency); 
int day = comp.MaturityDate.GetValueOrDefault(DateTime.Today).Day; 
DateTime countFrom = comp.EffectiveDate.GetValueOrDefault(DateTime.Today); 

return new DateTime(countFrom.Year, countFrom.Month, day).AddMonths(monthCount); 

年,月和日參數描述不可表示的日期時間?爲什麼?從DateTime返回時出錯

+0

是什麼這個錯誤會回來嗎? – 2011-02-01 15:54:44

+0

代碼下面的文本是錯誤。 – slandau 2011-02-01 15:55:39

回答

5

如果MaturityDate爲1/31/2011而EffectiveDate爲2/28/2011,那麼您的代碼將嘗試創建不存在的日期。

0

也許這種做法將有助於:

如果你想獲得是從指定的日期一個月日期,使用AddMonths

DateTime startDate = DateTime.Parse("1/31/2011"); 
DateTime endDate = startDate.AddMonths(1); 

這裏,endDate = 2/28/2011.