Getting dates into m/d/yyyy format

I’ve tried the simple_date_select plugin and it works as advertised
(Thank you so much!), that is it converts the unwieldy default date
selection boxes into a single text field with the default date format
like yyyy-mm-dd. And, I played with the extension to that plugin
proposed by Jeremy E. that uses strftime(’%m/%d/%Y’) to get it
reformatted like mm/dd/yyyy (Thank you, too, Jeremy).

My problem is that I can’t quite get strftime to format the dates
exactly as I’d like to see them, which is like 6/3/2006 (no zero or
space before the 6 and no zero or space before the 3). Being new to
Ruby, I’m weak on Ruby syntax. Jeremy’s suggested code is:
def to_date_select_tag(options = {})
to_input_field_tag(‘text’, {‘size’=>‘10’,

I tried to substitute a block {} for the expression
value.strftime(’%m/%d/%Y’) and failed miserably. Can anyone help me out
with some expression to convert a date string like 06/03/2006 to one
like 6/3/2006 that I can plug into the above method?

Thanks, this forum has been SOOOO helpful!


How about

date =


There’s one more item to consider here, and that’s how to treat nil
dates. I did figure out the answer to this one, so I’m posting the
solution here for others who might want to alter the plugin similarly to
get a m/d/yyyy format:

Replace the plugin line
to_input_field_tag(‘text’, {‘size’=>‘10’}.merge(options))

if value.nil? then
to_input_field_tag(‘text’, {‘size’=>‘10’}.merge(options))
to_input_field_tag(‘text’, {‘size’=>‘10’,

I hope this helps others. I haven’t tried altering the datetime portion
of the plugin because I don’t need datetimes, but I imagine similar code
would be needed there as well.


Wow, Long, that was perfect!