addmonth method

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

Hi all,

How exactly does the addmonth method of the datetime structure work? Does it
simply add the number of months to the date or does it actually enumerate
days in each month for that many months, taking into account leap years and
give an accurate final date?

TIA,
PR
 
I am not sure what you mean take in account leap year, et al, unless you are
assuming a month is a cycle that has a set period, like 30 days. The
addmonth() adds months, ie:

9/12/2002
addmonth(12)
9/12/2003

There is really nothing to take in account here, leap year or otherwise.

--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA

**********************************************************************
Think outside the box!
**********************************************************************
 
You are right by looking at it like a cycle. I was looking for a way to
accurately calculate a final date say 48 months from now - going on a day
basis.

thanks.
 
For this, try add days, or create your own method that adds 30 days for each
one unit (or whatever increment you desire). something like:

public void AddMonth(int monthNum, DateTime dt)
{
dt.AddDays((double)monthNum * 30)
}

I do not believe DateTime is sealed, so you could inherit from it and
override AddMonths().

--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA

**********************************************************************
Think outside the box!
**********************************************************************
 
Back
Top