1

I am trying to convert a string like "6 months ago" and "3 days ago" to a date/datetime.

Any ideas?

Thanks in advance!

2 Answers 2

4

The Chronic gem provides such a feature. (Github, RubyGems)

It can parse rather complex statements. For example

  • tomorrow
  • thursday
  • 7 hours ago
  • last night
  • fourteenth of june 2010 at eleven o'clock in the evening

can all be parsed.

Sign up to request clarification or add additional context in comments.

Comments

0

In rails, it can be done easily without other gems:

eval("3 days ago".gsub(" ","."))
# => Mon, 05 Aug 2013 13:31:06 UTC +00:00

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.