title: Get Milliseconds and NanoSeconds in SQL Server
body: <p>I'm trying to get Age, Months, Hours, Minutes, Seconds, MilliSeconds, NanoSeconds from DOB but I get an error when trying to get milliseconds or nanoseconds:</p>
  
  <blockquote>
    <p>Msg 535, Level 16, State 0, Line 3<br>
    The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.</p>
  </blockquote>
  
  <p>I was also try conversion method to solve but it can't - any ideas?</p>
  
  <p>Code:</p>
  
  <pre><code>DECLARE @date datetime
  
  SELECT @date = '2/11/1990 12:03:25.310 AM'
  
  SELECT (DATEDIFF(yy, @date, GETDATE()) - CASE WHEN (MONTH(@date) &gt; MONTH(GETDATE())) OR (MONTH(@date)
       = MONTH(GETDATE()) AND DAY(@date) &gt; DAY(GETDATE())) THEN 1 ELSE 0 END) AS "Age in Years", 
       (DATEDIFF(MONTH, @date, GETDATE()) - CASE WHEN DAY(@date) &gt; DAY(GETDATE()) THEN 1 ELSE 0 END) AS "Months", 
       (DATEDIFF(DAY, @date, GETDATE())) AS "DAYS",
       DATEDIFF(Hour,@date,GETDATE()) as [Hour],DATEDIFF(Minute,@date, GETDATE()) as [Minutes],DATEDIFF(Second,@date,GETDATE()) as [Seconds],
      RIGHT(CONVERT(VARCHAR, @date, 100),2) AS "AM/PM",DATEDIFF(MILLISECOND,@date,GETDATE()) as MiliSeconds
  </code></pre>