---
title: "TimeSpan not working"  
description: "TimeSpan not working"  
author: "Anonymous User"  
published: 2014-11-25  
updated: 2014-11-26  
canonical: https://www.mindstick.com/forum/12692/timespan-not-working  
category: "asp.net"  
tags: ["time"]  
reading_time: 1 minute  

---

# TimeSpan not working

Heres the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) I have re arranged, but still have same [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic), not able to find my start and [end](https://yourviews.mindstick.com/view/88503/us-iran-war-live-updates-trump-says-us-in-no-rush-to-end-iran-war) times on last [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page)? How do I do this?

```
public void start()    {        DateTime startTime = DateTime.Now;    }     protected void btnStart_Click(object sender, EventArgs e)    {        start();        Response.Redirect("~/end.aspx");    }public void end()    {        DateTime endTime = DateTime.Now;    }    protected void btnEnd_Click(object sender, EventArgs e)    {        end();        Response.Redirect("~/display.aspx");    }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](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) can [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept) on this?

## Replies

### Reply by Anonymous User

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);

or

TimeSpan timeSpent = end.Subtract(start);

To display it:

Console.WriteLine(timeSpent.TotalMilliseconds);

Now, go code! :)


---

Original Source: https://www.mindstick.com/forum/12692/timespan-not-working

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
