Ishan Bhutani

Ishan Bhutani

  • NA
  • 22
  • 1.2k

Time Difference

Mar 22 2017 6:17 AM
I am creating a quiz application and I want to calculate the time elapsed between the page load and the button click.
Here is the code I am trying but unable to calculate.The timeSpan show 0(Zero) as the difference even after hours.
 
Code Start
 
protected void Page_Load(object sender, EventArgs e)
{
   if (Page.IsPostBack == false)
   {
      dtAlgebraLoad = DateTime.Now;
      lblTimeLoad.Text = "Initial time: " + dtAlgebraLoad.ToString();
   }
}
protected void btnAlgebraSubmit_Click(object sender, EventArgs e)
{
   dtAlgebraNext = DateTime.Now;
   lblTimeSubmit.Text = dtAlgebraNext.ToString();
}
protected void btnAlgebraNext_Click(object sender, EventArgs e)
{
   TimeSpan timeSpan = dtAlgebraNext.Subtract(dtAlgebraLoad);
   lblTimeDifference.Text = timeSpan.ToString();
}
 
Code End
 
Can some help me with the code.

Answers (7)