Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# equivalent of VFP Date manipulation
Message
From
07/08/2003 06:47:24
 
 
To
06/08/2003 21:28:24
Czarina Joyce Villanueva
Innovision Systems International
Manila, Philippines
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00817537
Message ID:
00817595
Views:
18
Czarina,

When dealing with the DateTime class you will have to get used to dealing with the TimeSpan class when you want to express intervals (ie. 3 days 2 hours 12 minutes etc.) between DateTime instances.
DateTime myDateTime1 = new DateTime(2003, 1, 1);
DateTime myDateTime2 = new DateTime();
TimeSpan myTimeSpan  = new TimeSpan();

myDateTime2 = DateTime.Now;

// Calculate interval between 2 dates using Subtract method.
myTimeSpan = myDateTime1.Subtract(myDateTime2);

Console.WriteLine(myTimeSpan.Days.ToString());

// Calculate interval between 2 dates using overloaded operator.
myTimeSpan = myDateTime1 - myDateTime2.AddDays(100);

Console.WriteLine(myTimeSpan.Days.ToString());
As you can see from the code above the result using either of the 2 methods returns a TimeSpan instance from which we can deduce things like number of Days.

The DateTime class also provides overloaded operators and methods for performing additions and subtractions using TimeSpan instances.
Previous
Reply
Map
View

Click here to load this message in the networking platform