title: Convert Time value into Integer in sql server
body: <p>I need to <code>convert</code> <code>Time</code> value into <code>integer</code> value .</p>
  
  <p>For E.g:  If the <code>time</code> value is <code>'07:00 PM'</code> I need to <code>convert</code> it into <code>19</code>.</p>
  
  <p>I have tried below query to do this.</p>
  
  <pre><code>select CAST(substring(CONVERT(varchar,convert(smalldatetime,'07:00 PM'),114), 1,2) as int) as VALUE
  </code></pre>
  
  <p>It returns me the desired output. But it's taking too much time in case of <code>big transactions</code>. Can anyone suggest me an alternative solution ( a simple one perhaps)? </p>
  
  <p>I can't use  <code>datepart(hour, 'timevalue')</code>. Because there are data's with time value  <code>'00:00 AM'</code>and<code>'00:00 PM'</code>which through's conversion error<code>.</code>In This case I need to return the value as <code>0</code>.`</p>