# European Date Format (newbie!)

**URL:** <https://www.ruby-forum.com/t/european-date-format-newbie/151494>\
**Category:** Rails\
**Created:** [October 22, 2008, 7:22am UTC](https://www.ruby-forum.com/t/european-date-format-newbie/151494 "2008-10-22T07:22:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicktabs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@Nicktabs](https://www.ruby-forum.com/u/Nicktabs)\
**Post date:** [October 22, 2008, 7:22am UTC](https://www.ruby-forum.com/t/european-date-format-newbie/151494/1 "2008-10-22T07:22:17Z")

</div>

Rails 2.0

Hi there,

There are a few topics on here that relate to my problem but none are  
helping as i’m new to this and there are lots of confusing posts on  
google.

I need to chage the way dates are input and displayed in my app. This  
is for a european app so the dates need to work as DD/MM/YYYY not the  
America way.

Now I don’t mind keeping the datbase in the orginal Date format as I  
won’t be accessing it directly however I guess I need to wrtite  
something in my model to change the way the dates are done?

Anybody able to help?

Many thanks.

Nick

---

<div class="post-metadata">

**Author:** ![Nicktabs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@Nicktabs](https://www.ruby-forum.com/u/Nicktabs)\
**Post date:** [October 22, 2008, 9:46am UTC](https://www.ruby-forum.com/t/european-date-format-newbie/151494/2 "2008-10-22T09:46:59Z")

</div>

On 21 Oct 2008, at 22:21, Nicktabs wrote:

> something in my model to change the way the dates are done?  
> Showing them in European date format is easy, almost every  
> localization plugin out there provides it in some way and you can do  
> it yourself quite easily too. Input is a totally different matter, as  
> far as I know there is no transparent way to make Rails process  
> European date and number formats from input fields. I’ve implemented a  
> few hacky solutions in the past, like using method\_missing or  
> generating a number of new methods to convert one format to the other,  
> but in the end it doesn’t feel right at all.

There have been some discussions in the Rails i8n group about it, but  
those also seem to have died a silent death and localization in the  
next version is very basic (but easier to plugin on, although I still  
have serious doubts about date and number formats, since those would  
require quite some changes in the fundations of the framework).

I hope someone of the i8n people will chime in on this post and be  
able to tell you what to expect, I might be wrong in what I said (so  
hung up in a project I haven’t been able to follow the discussion).

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![Nicktabs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@Nicktabs](https://www.ruby-forum.com/u/Nicktabs)\
**Post date:** [October 22, 2008, 10:49am UTC](https://www.ruby-forum.com/t/european-date-format-newbie/151494/3 "2008-10-22T10:49:45Z")

</div>

> I need to chage the way dates are input and displayed in my app. This  
> is for a european app so the dates need to work as DD/MM/YYYY not the  
> America way.
> 
> Now I don’t mind keeping the datbase in the orginal Date format as I  
> won’t be accessing it directly however I guess I need to wrtite  
> something in my model to change the way the dates are done?

I use the DATE format in the database. I convert the format on input  
and output.

Input from a form:  
def convert\_european\_date(date)

```
# Authorize ISO date
return date unless (/^\d{4}-\d{2}-\d{2}$/).match(date).nil?

# Convert european date
match = /(\d{1,2}).(\d{1,2}).(\d{2,4})/.match(date)
begin
  Date.new(match[3].to_i, match[2].to_i, match[1].to_i)
rescue
  return false
end

```

end

Display:  
\<%= due\_date.to\_s(:european) %\>

In initializers/date\_formats.rb:  
ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS.merge!  
(:european =\> ‘%d/%m/%Y’)  
ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS.merge!  
(:american =\> ‘%m/%d/%Y’)

Christian

---

<div class="post-metadata">

**Author:** ![Nicktabs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@Nicktabs](https://www.ruby-forum.com/u/Nicktabs)\
**Post date:** [October 22, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/european-date-format-newbie/151494/4 "2008-10-22T21:26:24Z")

</div>

On Tue, Oct 21, 2008 at 4:21 PM, Nicktabs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need to chage the way dates are input and displayed in my app. This  
> is for a european app so the dates need to work as DD/MM/YYYY not the  
> America way.

Not a complete solution, but building blocks:

[http://ruby-doc.org/core/classes/Date.html#M000655](http://ruby-doc.org/core/classes/Date.html#M000655)  
[http://ruby-doc.org/core/classes/Date.html#M000620](http://ruby-doc.org/core/classes/Date.html#M000620)  
[http://www.ruby-doc.org/core/classes/Time.html#M000297](http://www.ruby-doc.org/core/classes/Time.html#M000297)

puts Date.strptime(“22/10/2008”, “%d/%m/%Y”).strftime(“%d/%m/%Y”)
