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 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*
```
Date.parse("10/20/2013")
=> ArgumentError: invalid date

```

to

```
Date.parse("20/10/2013")
=> Sun, 20 Oct 2013

```