title: How Do I Add 15 Minutes To A Datetime In Ruby Only Between Certain Hours Of The Day?
body: <p>I'm a full time SQL Server database developer, but I'm looking to start utilizing Ruby for certain management tasks.  Also, I'm trying to take my Rails skills to the next level.  I'm great with SQL, but weak in programming languages (I'm working hard to fix that!).  Here is my question:</p>
  
  <p>I want to write a simple loop that will seed my database for a rails application for an appointments model.  I want to start with a Monday date (let's say March 19, 2012) and I want to end with a Friday date (March 23, 2012).  I want to start at 9am on each day, and I want to end at 5pm each day.  I want my appointments in 15 minute intervals.</p>
  
  <p>Currently, I have a simple loop that will add the 15 minutes to a parsed time.  However, I want to add 15 minutes only between the hours of 9am and 5pm each day.  Here is my code so far:</p>
  
  <pre><code>s = Time.parse("March 19, 2012, 9:00 AM")
  e = Time.parse("March 23, 2012 5:00 PM") + 15 * 60
  
  while s &lt; e
    puts "#{s} "
    s+=15 * 60
  end
  </code></pre>
  
  <p>I have a perfect list of dates from the above code (although I know there's probably a much better way to do it), but as I said, I want to limit my results so that I don't seed my database table with a bunch of useless dates that I constantly have to deal with in my Rails application.</p>
  
  <p>Any advice would be greatly appreciated.  Thank you in advance for your help!</p>