# using strptime to create a date object

**URL:** <https://discuss.rubyonrails.org/t/using-strptime-to-create-a-date-object/32352>\
**Category:** rubyonrails-talk\
**Created:** [July 24, 2008, 11:55pm UTC](https://discuss.rubyonrails.org/t/using-strptime-to-create-a-date-object/32352 "2008-07-24T23:55:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_L](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dave\_L](https://discuss.rubyonrails.org/u/Dave_L)\
**Post date:** [July 24, 2008, 11:55pm UTC](https://discuss.rubyonrails.org/t/using-strptime-to-create-a-date-object/32352/1 "2008-07-24T23:55:38Z")

</div>

Im wondering if it is possible to turn a string with a month name such as: "July 20, 2008" directly into a date object using strptime. If this is not possible am I going to have to write my own function to do this? I was thinking I could have and array with all the months and shuffle through it to get the month number and then use that to create a date object.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 25, 2008, 12:08am UTC](https://discuss.rubyonrails.org/t/using-strptime-to-create-a-date-object/32352/2 "2008-07-25T00:08:02Z")

</div>

Dave Lynam wrote:

> Im wondering if it is possible to turn a string with a month name such as: "July 20, 2008" directly into a date object using strptime. If this is not possible am I going to have to write my own function to do this? I was thinking I could have and array with all the months and shuffle through it to get the month number and then use that to create a date object.

Date.strptime("July 20, 2008", "%b %d, %Y")

---

<div class="post-metadata">

**Author:** ![Elad\_Meidar](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@Elad\_Meidar](https://discuss.rubyonrails.org/u/Elad_Meidar)\
**Post date:** [July 25, 2008, 12:13am UTC](https://discuss.rubyonrails.org/t/using-strptime-to-create-a-date-object/32352/3 "2008-07-25T00:13:59Z")

</div>

Something like the chronic gem at [http://chronic.rubyforge.org/](http://chronic.rubyforge.org/) maybe?
