[edit] Using the DateTime.AddMonths Method
To use the DateTime.AddMonths method you will not specify a timespan. You must specify the amount of month you want to add. It accepts an int value so it can NOT calculate partial Months. Remember, a timespan must NOT be used with DateTime.AddMonths.
[edit] Syntax
DateTime.AddMonths(<int>)
[edit] Example 1:
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
Console.WriteLine("today: " + today.ToString());
today = today.AddMonths(3);
Console.WriteLine("New Date: " + today.ToString());
Console.Read();
}
}
Output:
today: 4/5/2007 8:28:51 PM
New Date: 7/5/2007 8:28:51 PM
As you can see the AddMonths method simply added 3 months to the current date.
<-- DateTime Tutorial
|