title: Add Time from TimeSpan Object in Powershell
body: <p>This has been driving me nuts, and it's got to be something simple I'm missing.</p>
  <p>I'm simply trying to get the total hours from a <code>TimeSpan</code> object and use that to add to a <code>DateTime</code> object.</p>
  <pre><code>$mytime = &quot;1/1/2020 10:00:00&quot;
  $hours = (New-TimeSpan -Start $mytime).TotalHours
  Get-Date
  (Get-Date $mytime).AddHours($hours)
  </code></pre>
  <p>The result is</p>
  <blockquote>
  <p>Wednesday, February 5, 2020 11:25:37 AM</p>
  <p>Wednesday, February 5, 2020 11:25:37 AM</p>
  </blockquote>
  <p>In the above, the time doesn't change!  However if I just assign a value to <code>$hours</code>, it works fine.</p>
  <pre><code>$mytime = &quot;1/1/2020 10:00:00&quot;
  $hours = 100
  Get-Date
  (Get-Date $mytime).AddHours($hours)
  </code></pre>
  <blockquote>
  <p>Wednesday, February 5, 2020 11:25:37 AM</p>
  <p>Sunday, January 5, 2020 5:00:01 AM</p>
  </blockquote>
  <p>I've tried all manner of variable assignments and casting, but no matter what I do I can't get the <code>TotalHours</code> value to work.  Why can't I use <code>$hours</code>? <code>TotalHours</code> is supposed to be a normal <code>double</code>, and even if I cast it to <code>double</code> (<code>[double]$hours = New-Timespan...</code>) nothing changes.</p>