5
Answers

calculating time duration

Ask a question
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#

Answers (5)