# Parsing string to datetime month & day reversed

**URL:** <https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490>\
**Category:** Rails\
**Created:** [December 29, 2007, 4:34am UTC](https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490 "2007-12-29T04:34:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsc\_dev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/13edae/32.png) [@bsc\_dev](https://www.ruby-forum.com/u/bsc_dev)\
**Post date:** [December 29, 2007, 4:34am UTC](https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490/1 "2007-12-29T04:34:28Z")

</div>

Hello,

I have a parse that reads in a file and populates my database. The  
problem is that when I use Time.parse it interprets the second digit as  
the month rather than the day.

For example:  
Input: 12-04-2007 21:15:56  
Shows as Apr 12, 2007

Controller Line: wanted.earlist\_pre\_order = Time.parse(items[12])

Any help would be greatly appreciated.

Barb

---

<div class="post-metadata">

**Author:** ![bsc\_dev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/13edae/32.png) [@bsc\_dev](https://www.ruby-forum.com/u/bsc_dev)\
**Post date:** [December 29, 2007, 11:33am UTC](https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490/2 "2007-12-29T11:33:19Z")

</div>

Barb W. wrote:

> Hello,
> 
> I have a parse that reads in a file and populates my database. The  
> problem is that when I use Time.parse it interprets the second digit as  
> the month rather than the day.
> 
> For example:  
> Input: 12-04-2007 21:15:56  
> Shows as Apr 12, 2007
> 
> Controller Line: wanted.earlist\_pre\_order = Time.parse(items[12])
> 
> Any help would be greatly appreciated.
> 
> Barb

Well that’s not an error. It depends on where you live. I think you can  
try somewhere the strftime method

---

<div class="post-metadata">

**Author:** ![bsc\_dev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/13edae/32.png) [@bsc\_dev](https://www.ruby-forum.com/u/bsc_dev)\
**Post date:** [December 29, 2007, 3:06pm UTC](https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490/3 "2007-12-29T15:06:01Z")

</div>

On Dec 28, 2007 10:34 PM, Barb W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Controller Line: wanted.earlist\_pre\_order = Time.parse(items[12])
> 
> Any help would be greatly appreciated.

Date/Time.parse uses a variety of heuristics in an attempt to deal  
with the various ways we present dates around the world.

I think that using “-” for the separator triggers it to interpret the  
date in EU format dd-mm-yyyy and a ‘/’ causes it to use the US  
interpretation mm/dd/yyyy

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![bsc\_dev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/13edae/32.png) [@bsc\_dev](https://www.ruby-forum.com/u/bsc_dev)\
**Post date:** [December 31, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/parsing-string-to-datetime-month-day-reversed/124490/4 "2007-12-31T18:12:28Z")

</div>

On 12/28/07, Barb W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any help would be greatly appreciated.  
> You can use strptime to parse dates/times with unusual formats:

[http://www.ruby-doc.org/core/classes/DateTime.html#M002824](http://www.ruby-doc.org/core/classes/DateTime.html#M002824)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
