Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime object

Status
Not open for further replies.

buxtonicer1

Programmer
Sep 20, 2006
82
GB
Is there a simple way to compare to DateTime values, and as a result add and subtract them.
 
Look at DateTime.Add and DateTime.Subtract. You should also look at the TimeSpan class. DateTime.Add takes a TimeSpan parameter and .Subtract takes either a DateTime parameter, which returns a TimeSpan, or a TimeSpan parameter, which returns a DateTime. TimeSpan has Days, Hours, Minutes, and Seconds properties that you can use without having to do the conversions yourself.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Just subtract them. The result is a TimeSpan object.
Code:
TimeSpan ts = MyDate1 - MyDate2;


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top