Use the Subtract() method to subtract a TimeSpan from a DateTime : TimeSpan : Date Time C# Examples


C# Examples » Date Time » TimeSpan »

 

Use the Subtract() method to subtract a TimeSpan from a DateTime









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {

        
        DateTime  myDateTime  =  DateTime.Parse("1/11/2004  23:10:30");

        
        TimeSpan  myTimeSpan  =  new  TimeSpan(1,  2,  4,  10);
        DateTime  myDateTime7  =  myDateTime.Subtract(myTimeSpan);
        Console.WriteLine("myTimeSpan  =  "  +  myTimeSpan);
        Console.WriteLine("myDateTime6.Subtract(myTimeSpan)  =  "  +  myDateTime7);

    }

}
    
   
  
   



Output

myTimeSpan = 1.02:04:10
myDateTime6.Subtract(myTimeSpan) = 31/10/2004 9:06:20 PM


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» TimeSpan