# Using strptime to create a date object

**URL:** <https://www.ruby-forum.com/t/using-strptime-to-create-a-date-object/144066>\
**Category:** Rails\
**Created:** [July 25, 2008, 1:56am UTC](https://www.ruby-forum.com/t/using-strptime-to-create-a-date-object/144066 "2008-07-25T01:56:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 25, 2008, 1:56am UTC](https://www.ruby-forum.com/t/using-strptime-to-create-a-date-object/144066/1 "2008-07-25T01:56:21Z")

</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:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 25, 2008, 2:08am UTC](https://www.ruby-forum.com/t/using-strptime-to-create-a-date-object/144066/2 "2008-07-25T02:08:02Z")

</div>

Dave L. 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:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 25, 2008, 2:14am UTC](https://www.ruby-forum.com/t/using-strptime-to-create-a-date-object/144066/3 "2008-07-25T02:14:28Z")

</div>

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

On Jul 25, 3:08 am, Jeremy Weiskotten \<rails-mailing-l…@andreas-
