title: Conversion between timespan and date using vb.net
body: <p>I'm running an application in which I'm able to obtain the required times, however when I try to deduct one value from another it comes up with error message stating conversion from date type cannot happen to timespan. The variables I use are shown below:</p>
  
  <pre><code>Dim downtime As TimeSpan
  Dim uptime As TimeSpan 
  
  Dim errortime As String() = lb_critical.SelectedItem.Split({" | "}, StringSplitOptions.RemoveEmptyEntries)
  Dim errortimefound As DateTime = Convert.ToDateTime(errortime(0).ToString())
  downtime = DateTime.Now - errortimefound
  uptime = DateTime.Now - Convert.ToDateTime(downtime.ToString())
  </code></pre>
  
  <p>When I run this I get error with downtime variable. </p>
  
  <p>To try and resolve, I tried converting the variables to all DateTime before deducted them, had a look on the internet but wasn't successful. </p>
  
  <p>Could anyone identify what I am doing wrong here.</p>
  
  <p>Thank you Andrew for improved code, but unfortunately I'm still getting the error. Please see the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/kXo8O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kXo8O.png" alt="enter image description here"></a></p>