G
Guest
Hello all,
I've been trying to determine the difference in minutes between two DateTime objects (startTime and endTime) in C# using the TimeSpan object (ts). I am populating the two DateTime objects from the click of two buttons (start and stop) that I have placed on an ASP.NET webform. I have attempted to follow the many examples that are available on the web yet I'm finding that instead of returning the difference in minutes, my code is only returning the minute value of my second DateTime object (endTime).
//Object Definitions
DateTime startTime;
DateTime endTime;
TimeSpan ts;
//Clicking a buton on my webform called "start" processes:
startTime = DateTime.Now; //opening time stamp
//Clicking button called "end" processes:
endTime = DateTime.Now; //closing time stamp
ts = endTime.Subtract(startTime); //calculate timespan
lblTimeSpan.Text = ts.Minutes.ToString(); //write minutes to label
The results are the same if I replace the Subtract method with:
ts = endTime - startTime; //calculate timespan
If I try to return the property of TotalMinutes instead of Minutes, I receive a value that is typed as a double and cannot seem to format into anything meaningful.
Any insight into what I may be doing incorrectly would be greatly appreciated.
Thank you for your time,
Justin.
I've been trying to determine the difference in minutes between two DateTime objects (startTime and endTime) in C# using the TimeSpan object (ts). I am populating the two DateTime objects from the click of two buttons (start and stop) that I have placed on an ASP.NET webform. I have attempted to follow the many examples that are available on the web yet I'm finding that instead of returning the difference in minutes, my code is only returning the minute value of my second DateTime object (endTime).
//Object Definitions
DateTime startTime;
DateTime endTime;
TimeSpan ts;
//Clicking a buton on my webform called "start" processes:
startTime = DateTime.Now; //opening time stamp
//Clicking button called "end" processes:
endTime = DateTime.Now; //closing time stamp
ts = endTime.Subtract(startTime); //calculate timespan
lblTimeSpan.Text = ts.Minutes.ToString(); //write minutes to label
The results are the same if I replace the Subtract method with:
ts = endTime - startTime; //calculate timespan
If I try to return the property of TotalMinutes instead of Minutes, I receive a value that is typed as a double and cannot seem to format into anything meaningful.
Any insight into what I may be doing incorrectly would be greatly appreciated.
Thank you for your time,
Justin.