<p>In Ruby, I'm trying to do the following.</p>

<pre><code>def self.stats(since)
  return Events.find(:all, :select =&gt; 'count(*) as this_count', :conditions =&gt; ['Date(event_date) &gt;= ?', (Time.now - since)]).first.this_count
end
</code></pre>

<p>where "since" is a string representing an amount of time ('1 hour', '1 day', '3 days') and so on. Any suggestions?</p>

[{'answer_id': 40580, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 2, 'selected': False, 'text': '<p>Try using <a href="http://chronic.rubyforge.org/" rel="nofollow noreferrer">Chronic</a> to parse the date strings into actual datetime objects.</p>\n'}, {'answer_id': 40822, 'author': 'Wieczo', 'author_id': 4195, 'author_profile': 'https://Stackoverflow.com/users/4195', 'pm_score': 3, 'selected': True, 'text': '<p>I hacked this together with the ActiveSupport gem:</p>\n\n<pre><code>require \'active_support\'\n\ndef string_to_date(date_string)\n  parts = date_string.split\n  return parts[0].to_i.send(parts[1])\nend\nsinces = [\'1 hour\', \'1 day\', \'3 days\']\n\nsinces.each do |since|\n  puts "#{since} ago: #{string_to_date(since).ago(Time.now)}"\nend\n</code></pre>\n\n<p>[edit] To answer your question, you might try it like that:</p>\n\n<pre><code>:conditions =&gt; [\'Date)event_date) &gt;= ?\', (string_to_date(since).ago(Time.now))]\n</code></pre>\n'}, {'answer_id': 20395024, 'author': 'RubenCaro', 'author_id': 1883905, 'author_profile': 'https://Stackoverflow.com/users/1883905', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with <a href="https://stackoverflow.com/a/40580/1933902">John Millikin</a>. <a href="http://chronic.rubyforge.org/" rel="nofollow noreferrer">Chronic</a>, or even your own helpers, would be a much lighter and effective dependency to carry than whole ActiveSupport, assuming you are not already trapped inside Rails.</p>\n'}]
['https://Stackoverflow.com/questions/40577', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4322/']