2011-02-01 70 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.