How do I get the time difference between two DateTime objects using C#?
How do I get the time difference between two DateTime objects using C#?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following example demonstrates how to do this:
When executed this prints “30” since there is a 30 minute difference between the date/times.
The result of
DateTime.Subtract(DateTime x)is a TimeSpan Object which gives other useful properties.