title: get only hour from datetime
body: <p>how to extract only hour from date and time and convert it to integer so that I can compare to integer??</p>
  
  <p>e.g.</p>
  
  <p>datetime = 2013-02-01 10:24:36.000 i.e in the date and time data type</p>
  
  <p>then </p>
  
  <p>hour = take hour only i.e. 10 </p>
  
  <p>then</p>
  
  <p>hour for comparision = Convert.ToInt32(time);</p>
  
  <p><strong>I have try this to item.StartTime which is date and time:</strong></p>
  
  <pre><code>var time = String.Format("{HH}", (DateTime)item.StartTime);
  var hour = Convert.ToInt32(time);
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>Input string was not in a correct format.
  </code></pre>