Link to home
Start Free TrialLog in
Avatar of Jacque Scott
Jacque ScottFlag for United States of America

asked on

Get difference between two times

I have a start time and an end time.  I need the difference between the two.

I am new to C# and need the best way to do this.  I am sure this is wrong but this is basically what I need to do.

            DateTime StartTime = DateTime.Now;
            DateTime EndTime = DateTime.Now;

 label1.Text = "Total time to do project: " + DateDiff(StartTime, EndTime);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jacque Scott

ASKER

Thank you
*No Points*

Shaun is correct.  Proof of concept:
using System;

namespace EE_Q28713211
{
	class Program
	{
		static void Main(string[] args)
		{
			DateTime start = new DateTime(2015, 11, 9, 4, 30, 00);
			DateTime end = new DateTime(2015, 11, 9, 5, 15, 00);
			Console.WriteLine("Difference between {0} and {1} is {2} minutes.", start.ToString("h:mm"), end.ToString("h:mm"), (end - start).TotalMinutes);
			Console.ReadLine();
		}
	}
}

Open in new window

Produces the following output -User generated image-saige-