# I have some challenges with the date

**URL:** <https://www.ruby-forum.com/t/i-have-some-challenges-with-the-date/156943>\
**Category:** Ruby\
**Created:** [January 5, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/i-have-some-challenges-with-the-date/156943 "2009-01-05T17:11:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 5, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/i-have-some-challenges-with-the-date/156943/1 "2009-01-05T17:11:03Z")

</div>

here i have a string date like this. 02/01/2009 : Format is DD/MM/YY  
however my date.parse switches the month and the day.  
how do i fix it.

irb(main):011:0\> Date.parse(“02/01/2009”).strftime(’%Y-%m-%d’)  
=\> “2009-02-01”

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 5, 2009, 5:16pm UTC](https://www.ruby-forum.com/t/i-have-some-challenges-with-the-date/156943/2 "2009-01-05T17:16:55Z")

</div>

On Jan 5, 2009, at 10:10 AM, Junkone wrote:

> here i have a string date like this. 02/01/2009 : Format is DD/MM/YY  
> however my date.parse switches the month and the day.  
> how do i fix it.
> 
> irb(main):011:0\> Date.parse(“02/01/2009”).strftime(’%Y-%m-%d’)  
> =\> “2009-02-01”

You can specify a format for the parse:

> > Date.strptime(“02/01/2009”, “%d/%m/%Y”).to\_s  
> > =\> “2009-01-02”

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 5, 2009, 5:18pm UTC](https://www.ruby-forum.com/t/i-have-some-challenges-with-the-date/156943/3 "2009-01-05T17:18:41Z")

</div>

Junkone wrote:

> here i have a string date like this. 02/01/2009 : Format is DD/MM/YY  
> however my date.parse switches the month and the day.  
> how do i fix it.
> 
> irb(main):011:0\> Date.parse(“02/01/2009”).strftime(’%Y-%m-%d’)  
> =\> “2009-02-01”

> > Date.strptime(“02/01/2009”,"%d/%m/%Y").to\_s  
> > =\> “2009-01-02”

HTH,  
Sebastian
