title: How to detect the more close period using SQL Server
body: <p>If I have two <code>datetime</code> variables like this :</p>
  
  <pre><code>ST : 2016-02-07 08:00:00.000
  END: 2016-02-07 16:00:00.000
  </code></pre>
  
  <p>Now if I have a third <code>datetime</code> variable like this :</p>
  
  <pre><code>INSERTED : 2016-02-07 17:00:00.000
  </code></pre>
  
  <p>Is there some function to detect which period more close to the <code>INSERTED</code></p>
  
  <p>I mean in my example it will be <code>END:2016-02-07 16:00:00.000</code></p>