Question: I have a Mongoid field that is of type Date. I'm having all sorts of trouble searching for documents against this specific field. I receive dates as a string in this format: `10/20/2013`. I thought something like `Date.parse("10/20/2013")` or `"10/20/2013".to_date` would be good enough to let me do something like `MyModel.find_by(datefield: date_result)` but this is giving me a ton of ArgumentError out of range type issues.

What's the easiest way to turn "10/20/2013" into a simple `Date` object that I can use to query against databases?

Answer: 
You get this:

```
Date.parse("10/20/2013")
ArgumentError: invalid date

```

The problem is `10/20`. Ruby is an international language, and the values `10` and `20` are somewhat ambiguous. In the U.S. the "standard" date format is "MMDDYYYY", or `%m%d%Y` in date parsing terms. The majority of the world uses a different standard though, "DDMMYYYY" or `%d%m%Y`. Ruby uses the second format, with day first.

Looking at the difference, it's easy to see why `Date.parse` would be confused and complain. `10` is a sensible day, but `20` is nonsense as far as a month, so Ruby rejects it.

You can fix this by forcing the pattern used for parsing:

```
Date.strptime('10/20/2013', '%m/%d/%Y')
# => #<Date: 2013-10-20 ((2456586j,0s,0n),+0s,2299161j)>

```
You can use [`strptime`](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/DateTime.html#method-c-strptime):

```
Date.strptime('10/20/2013', '%m/%d/%Y')
=> <Date: 2013-10-20 ((2456586j,0s,0n),+0s,2299161j)>

```

Read [this](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/DateTime.html#method-i-strftime) a list of possible *formats*