title: How do I subtract TimeSpan and DateTime?
body: <p>I have placed a countdown timer which shows remaining time to complete the exam.</p>
  
  <p>I am trying to calculate the total time taken by the user to complete the exam.</p>
  
  <p>To calculate this, I subtracted the <code>end_time</code> of the exam with the remaining time shows in the countdown timer but I am getting current date in the output .For example <code>-09:04:05.1564371</code>...here it is the time when I ran the code.</p>
  
  <p>I don't know where I am making mistake. Have a look at my code show me where I am making mistake and what is the solution.</p>
  
  <p><b> Examdemo.aspx.cs :- </b></p>
  
  <pre><code>public partial class Student_Examdemo : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!Page.IsPostBack || Session["end_t"] == null)
          {
               DateTime start_time = DateTime.Now;
               DateTime end_time = start_time.AddMinutes(3);
               Session["end_t"] = end_time;
          } 
      }
  
      protected void timer1_tick(object sender, EventArgs e)
      {
           DateTime dt = (DateTime)Session["end_t"];
           DateTime dt_curr = DateTime.Now;
           TimeSpan ts = dt - dt_curr;
           lblTimer.Text = ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString();
  
           if (ts.Minutes == 0)
           {
               timer1.Enabled = false;
               Response.Redirect("/Student/Result.aspx");
           }
  
          TimeSpan usedTime = ts.Subtract(dt.TimeOfDay); //calculating the total time taken by user
          Session["takentime"] = usedTime.ToString(); //storing the calculated time in the session
      }
  
      protected void btn_Click(object sender, EventArgs e)
      {
          //statements
  
          Response.Redirect("/Student/Result.aspx?Score=" + Label2.Text +"&amp;AttemptedQues=" +Label3.Text+ "&amp;CorrectAns=" +Label4.Text);
      }
  }
  </code></pre>
  
  <p><b> Result.aspx.cs :- </b></p>
  
  <pre><code>public partial class Student_Result : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          Label1.Text = Request.QueryString["Score"];
          Label2.Text = Request.QueryString["AttemptedQues"];
          Label3.Text = Request.QueryString["CorrectAns"];
          Label5.Text = Session["takentime"] as string; //displaying the calculated time...got output like this : '-09:04:05.1564371'
      }
  }
  </code></pre>