title: how to use datepart with date in sql server
body: <p>I am working on an sql query where i want to attach datepart with time part. in the time part minute will be 20,40,59. and second will be always 00. For this i used the following query: Because i have report of only 20 minute of duration like 0-20 minute, 21-40 minute, and 41-59 minute of any hour.</p>
  
  <pre><code>DECLARE @RandomDate datetime
  DECLARE @HH INT
  DECLARE @MM INT
  DECLARE @S INT=00
  
  
  SELECT    @RandomDate=
  DATEADD(day,ROUND(DATEDIFF(day,GETDATE(),GETDATE())*(CHECKSUM(NEWID())), 5),
  DATEADD(second, CHECKSUM(NEWID()) % 48000, GETDATE())) 
  
  
  SELECT @HH= DATEPART(hour,@RandomDate),@MM=DATEPART(MINUTE,@RandomDate)
  
  
  SELECT  @RandomDate,@HH,@MM,@S
  
  
  SELECT CONVERT(DATE,@RandomDate)+ 
  DATEPART(hour,@RandomDate)+DATEPART(MINUTE,@RandomDate)+00
  </code></pre>
  
  <p>But it is showing error as </p>
  
  <pre><code>Operand type clash: date is incompatible with int
  </code></pre>
  
  <p>at the position</p>
  
  <pre><code>SELECT CONVERT(DATE,@RandomDate)+ 
  DATEPART(hour,@RandomDate)+DATEPART(MINUTE,@RandomDate)+00
  </code></pre>