how to calculate the time duration? - TechRepublic
Question
April 3, 2010 at 06:13 AM
heaven23

how to calculate the time duration?

by heaven23 . Updated 16 years, 3 months ago

hi.. please check this code of mine:

protected void Button4_Click(object sender, EventArgs e)
{
DateTime dt1;
DateTime dt2;

string currenttime1 = DateTime.Now.ToLongTimeString();
string currenttime2 = DateTime.Now.ToLongTimeString();
TextBox2.Text = currenttime2;

dt1 = Convert.ToDateTime(currenttime1);
dt2 = Convert.ToDateTime(currenttime2);

TimeSpan ts = dt1 – dt2;

int hours = ts.Hours;
int min = ts.Minutes;

string finalMin = Convert.ToString(min);

TextBox3.Text = finalMin;

—- i’m having a web page that calculated time duration when the user press the stop button.. but the output of this code is always zero.. what is my error?
thanks in advance..
–im using asp.net and C#

This discussion is locked

All Comments