title: T-SQL Pass constant value into procedure/function
body: <p>I recently noticed DateDiff isn't very accurate, so wanted to write a more accurate version</p>
  
  <p>Example of datediff not being accurate</p>
  
  <pre><code>DECLARE @sTime as DATETIME ='12/31/2013 23:59:59'
  DECLARE @eTime as DATETIME ='01/01/2014 00:00:00'
  SELECT 
      DateDiffYears   = DATEDIFF(YEAR, @sTime, @eTime)
  ,   DateDiffMonths  = DATEDIFF(MONTH, @sTime, @eTime)
  ,   DateDiffDays    = DATEDIFF(DAY, @sTime, @eTime)
  ,   DateDiffHours   = DATEDIFF(HOUR, @sTime, @eTime)
  ,   DateDiffMinutes = DATEDIFF(MINUTE, @sTime, @eTime)
  ,   DateDiffSeconds = DATEDIFF(SECOND, @sTime, @eTime)
  -- expected results: 0 year, 0 month, 0 day, 0 hour, 0 minute, 1 second
  -- actual results:   1 year, 1 month, 1 day, 1 hour, 1 minute, 1 second
  </code></pre>
  
  <p>My question is, can you pass in a constant value like DAY, SECOND, HOUR, etc into a custom function.</p>
  
  <p>Example:
  <code>
  SELECT dbo._newDateDiff(YEAR, @sTime, @eTime)
  </code></p>
  
  <p>I assume the only way to do this is to pass in a string value of 'YEAR', 'MONTH', etc. Is this true?</p>
  
  <p>Thanks,</p>