title: Compare time part of DateTime data type in SQL Server 2005
body: <p>How can I compare only the time portion of a DateTime data type in SQL Server 2005? For example, I want to get all records in which MyDateField is after a specific time. The following example is a very long and probably not fast way of doing this.
  I want all dates where MyDateField is greater than 12:30:50.400</p>
  
  <pre><code>SELECT *
  FROM   Table1
  WHERE      ((DATEPART(hour, MyDateField) = 12) AND (DATEPART(minute, MyDateField) = 30) AND (DATEPART(second, MyDateField) = 50) AND (DATEPART(millisecond, MyDateField) &gt; 400))
          OR ((DATEPART(hour, MyDateField) = 12) AND (DATEPART(minute, MyDateField) = 30) AND (DATEPART(second, MyDateField) &gt; 50))
          OR ((DATEPART(hour, MyDateField) = 12) AND (DATEPART(minute, MyDateField) &gt; 30))
          OR ((DATEPART(hour, MyDateField) &gt; 12))
  </code></pre>