Home > DeveloperSection > Forums > TimeSpan not working
Pawan Shukla
Pawan Shukla

Total Post:29

Posted on    November-25-2014 10:04 PM

 ASP.Net Time 

 1 Reply(s)
 1084  View(s)
Rate this:

Heres the code I have re arranged, but still have same problem, not able to find my start and end times on last page? How do I do this?


public void start()


        DateTime startTime = DateTime.Now;



    protected void btnStart_Click(object sender, EventArgs e)





public void end()


        DateTime endTime = DateTime.Now;


    protected void btnEnd_Click(object sender, EventArgs e)





public partial class display : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)


        TimeSpan timeSpent = endTime - startTime;


        lblDisplay.Text = string.Format("Time: {0}", timeSpent);



Now can anyone help me on this?

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    November-26-2014 12:14 AM

You do not need to convert this to a string.


DateTime start = DateTime.Now;

DateTime end = DateTime.Now;

(Note: Those two times above will be identical)


Once you have done that, you can use one of the other techniques shown above to get the timespan:


var timeSpent = (end - start);



TimeSpan timeSpent = end.Subtract(start);

To display it:



Now, go code! :)

Don't want to miss updates? Please click the below button!

Follow MindStick