Hi Marc,

>> On Thu, Jun 14, 2012 at 7:23 PM, Marc C. <li...@ruby-forum.com> wrote:
>>>
>>> Hello,
>>>
>>> I need to accept dates in a form using a text_field and not a
>>> date_select. Why? Well, because for users it's faster to type a date.
>>>
>>> But if I enter a simple date like "13/05/2012" (dd/mm/yyyy format), when
>>> I want to edit this register, in the text_field appears "2012-05-13".
>>>
>>> How can I change this behavior, so in the text_field appears
>>> "13/05/2012"?
>>>
>>> Thank you!
>>>


You can use the #strftime method to easily accomplish what you want.

ruby-1.9.2-p290 :001 > require 'date'
 => true
ruby-1.9.2-p290 :002 > d = Date.parse('2012-05-13')
 => #<Date: 2012-05-13 (4912121/2,0,2299161)>
ruby-1.9.2-p290 :003 > d.strftime('%d/%m/%Y')
 => "13/05/2012"

HTH,
Bill

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to