title: How can i loop through a daterange with different intervals?
body: <p>I have a daterange (from, to) that i want loop through an different intervals (daily, weekly, monthly, ...)</p>
  
  <p>How can i loop through this dateranges?</p>
  
  <p><em>Update</em></p>
  
  <p>Thanks for your answers, i came up with the following: </p>
  
  <pre><code>interval = 'week' # month, year
  start = from
  while start &lt; to
    stop  = start.send("end_of_#{interval}")
    if stop &gt; to
      stop = to
    end
    logger.debug "Interval from #{start.inspect} to #{stop.inspect}"
    start = stop.send("beginning_of_#{interval}")
    start += 1.send(interval)
  end
  </code></pre>
  
  <p>This will loop through a date range with intervals week, month or year and respects the beginning and end of the given interval. </p>
  
  <p>Since i did not mention this in my question i choosed the answer that pushed me into the right direction.</p>