# Date localization

**URL:** <https://www.ruby-forum.com/t/date-localization/175819>\
**Category:** Rails\
**Created:** [September 20, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/date-localization/175819 "2009-09-20T19:35:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 20, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/date-localization/175819/1 "2009-09-20T19:35:58Z")

</div>

Hi,

I have a model with start\_date and end\_date and a helper:

def period  
“#{start\_date} - #{end\_date}”  
end

in my view I have:

\<%= f.collection\_select :schedule\_id,  
@convention.schedules, :id, :period, {:selected =\> @schedule.id} %\>

How can I show :period localized, as \<%=l … won’t work.

Regards  
Arwed

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 20, 2009, 9:52pm UTC](https://www.ruby-forum.com/t/date-localization/175819/2 "2009-09-20T21:52:53Z")

</div>

2009/9/20 arwed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> I have a model with start\_date and end\_date and a helper:
> 
> def period  
> Â “#{start\_date} - #{end\_date}”

If you want the dates to appear as localised strings you must do it  
here. Formatting them as appropriate as you build the string. If I  
understand the question correctly.

Colin

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 20, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/date-localization/175819/3 "2009-09-20T22:32:06Z")

</div>

2009/9/20 arwed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> need is dd.mm.yyy  
> Have you tried #{l start\_date}  
> The #{ } syntax in a double quoted string just says drop into ruby and  
> work out the expression between the braces.  
> Alternatively if you always want the same format you can use  
> #{start\_date.strftime(some parameters to format it the way you want)}

Colin

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 20, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/date-localization/175819/4 "2009-09-20T22:01:40Z")

</div>

Hi Colin,

thanks for your reply.

I defined my date formats in /config/locales/de.yml but I don’t know  
how to format my dates in my model. In view I can do \<%=l  
@schedule.start\_date %\>.

Can you tell me how I can do that with #{start\_date}? The format I  
need is dd.mm.yyy

Regards  
Arwed

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 21, 2009, 9:32am UTC](https://www.ruby-forum.com/t/date-localization/175819/5 "2009-09-21T09:32:25Z")

</div>

Hi Colin,

I tried #{l start\_date}, but I doesn’t work.

I was hoping there was a way to use “l” in some way in my model. With  
strftime it works.

Thanks for your help

Regards  
Arwed

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [September 21, 2009, 10:22am UTC](https://www.ruby-forum.com/t/date-localization/175819/6 "2009-09-21T10:22:46Z")

</div>

2009/9/21 arwed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi Colin,
> 
> I tried #{l start\_date}, but I doesn’t work.
> 
> I was hoping there was a way to use “l” in some way in my model. With  
> strftime it works.

Possibly l is only available in views. In which case you would have  
to put the period method that uses “#{l @start-date} - #{l end-date}}”  
in the view helper.

Colin
