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.

Nitin SontakkeRank #264 · 9.6K reputationPosted Mar 22, 2017, 3:47 AM EDT
Abhinav AbhishekRank #2,198 · 642 reputationPosted Mar 22, 2017, 3:52 AM EDT
DateTime dt1 = DateTime.Parse(dtAlgebraLoad .Text);
DateTimedt2 = DateTime.Parse(dtAlgebraNext.Text);TimeSpan span = dt2 - dt1;Rafnas T PRank #280 · 8.8K reputationPosted Mar 22, 2017, 4:32 AM EDT
Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 22, 2017, 4:32 AM EDT
Nilesh ShahRank #42 · 34.2K reputationPosted Mar 22, 2017, 8:10 AM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 22, 2017, 9:24 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Mar 22, 2017, 10:08 AM EDT