Subtract duration from DateTime in CSharp
Description
The following code shows how to subtract duration from DateTime.
Example
using System;//from w ww. j a va2 s . c o m
public class MainClass{
public static void Main(String[] argv){
System.DateTime date1 = new System.DateTime(2014, 6, 3, 22, 15, 0);
System.DateTime date2 = new System.DateTime(2014, 12, 6, 13, 2, 0);
System.DateTime date3 = new System.DateTime(2014, 10, 12, 8, 42, 0);
System.TimeSpan diff1 = date2.Subtract(date1);
Console.WriteLine(diff1);
System.DateTime date4 = date3.Subtract(diff1);
Console.WriteLine(date4);
System.TimeSpan diff2 = date2 - date3;
Console.WriteLine(diff2);
System.DateTime date5 = date1 - diff2;
Console.WriteLine(date5);
}
}
The code above generates the following result.