slandau
slandau

Reputation: 24052

Error Coming back from DateTime

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);

Year, Month, and day parameters describe an unrepresentable datetime? Why?

Upvotes: 0

Views: 345

Answers (2)

DOK
DOK

Reputation: 32841

Perhaps this approach will help:

If you want to get the date that is one month from a specified date, use AddMonths:

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

Here, endDate = 2/28/2011.

Upvotes: 0

SLaks
SLaks

Reputation: 887451

If MaturityDate is 1/31/2011 and EffectiveDate is 2/28/2011, your code will try to create a non-existent date.

Upvotes: 5

Related Questions