[edit] Using the DateTime.AddMinutes Method
To use the DateTime.AddMinutes method you will not specify a timespan. You must specify the amount of minutes you want to add. It accepts a double value so it can calculate partial Minutes. Remember, a timespan must NOT be used with DateTime.AddMinutes.
[edit] Syntax
DateTime.AddMinutes(<double>)
[edit] Example 1:
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
Console.WriteLine("today: " + today.ToString());
today = today.AddMinutes(17);
Console.WriteLine("New Date: " + today.ToString());
Console.Read();
}
}
Output:
today: 4/5/2007 8:28:51 PM
New Date: 4/5/2007 8:45:51 PM
As you can see the AddMinutes method simply added 17 minutes to the current date.
[edit] Example 2:
This example will add partial minutes.
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
Console.WriteLine("today: " + today.ToString());
today = today.AddMinutes(1.2);
Console.WriteLine("New Date: " + today.ToString());
Console.Read();
}
}
Output:
today: 4/5/2007 8:45:50 PM
New Date: 4/5/2007 8:47:02 PM
As you can see the program added a partial minute and it also added the appropriate minutes.
<-- DateTime Tutorial
|