Create a TimeSpan representing 1 week and subtract from a DataTime : DateTime : Date Time C# Examples


C# Examples » Date Time » DateTime »

 

Create a TimeSpan representing 1 week and subtract from a DataTime









    
using  System;
class  MainClass
{
        public  static  void  Main(string[]  args)
        {
                TimeSpan  oneWeek  =  new  TimeSpan(4,  12,  0,  0)  +  new  TimeSpan(2,  12,  0,  0);
                        
                DateTime  now  =  DateTime.Now;

                //  Create  a  DateTime  representing  1  week  ago.
                DateTime  past  =  now  -  oneWeek;
                
                Console.WriteLine("Past    :  {0}",  past);
        
        }
}
    
   
  
   



Output

Past  : 18/03/2007 2:10:53 PM


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» DateTime