title: How to use intersect() function with date ranges in R
body: <p>Here is my code:</p>
  
  <pre><code>a&lt;-"2015-12-13 09:00:00"           
  b&lt;-"2015-12-13 12:00:00"
  c&lt;-interval(a,b)
  
  d&lt;-"2015-12-13 09:00:00"           
  e&lt;-"2015-12-13 12:00:00"
  f&lt;-interval(d,e)
  h&lt;-intersect(c,f)
  h
  </code></pre>
  
  <p>The values of <code>c</code>,<code>f</code> and <code>h</code> are:</p>
  
  <pre><code>&gt; h
  [1] 10800
  &gt; c
  [1] 2015-12-13 09:00:00 UTC--2015-12-13 12:00:00 UTC
  &gt; f
  [1] 2015-12-13 09:00:00 UTC--2015-12-13 12:00:00 UTC
  &gt; 
  </code></pre>
  
  <p>But, when I give a different date/time range. The intersect function does not work. For example:
  If I change the time of the variable d and e from <code>09:00:00-12:00:00</code> to <code>09:00:00 - 10:00:00</code>, I am expecting the <code>intersect</code> function to give me the minutes for 1 hour that is common.</p>
  
  <pre><code>a&lt;-"2015-12-13 09:00:00"           
  b&lt;-"2015-12-13 12:00:00"
  c&lt;-interval(a,b)
  
  d&lt;-"2015-12-13 09:00:00"           
  e&lt;-"2015-12-13 10:00:00"
  f&lt;-interval(d,e)
  h&lt;-intersect(c,f)
  h
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>numeric(0)
  &gt; c
  [1] 2015-12-13 09:00:00 UTC--2015-12-13 12:00:00 UTC
  &gt; f
  [1] 2015-12-13 09:00:00 UTC--2015-12-13 10:00:00 UTC
  </code></pre>
  
  <p>I get numeric(0). Can someone please help me with this.</p>