convert ruby date to string without losing format

Use Date#strftime there are so many options

require 'date'


date = Date.parse("Sun, 15 Sep 2013") # => #<Date: 2013-09-15 ((2456551j,0s,0n),+0s,2299161j)>

date.strftime("%a, %d %b %Y") # => "Sun, 15 Sep 2013"

strftime works well, however, if you find that you're using the same format in multiple places, you will find using the Rails Date#to_formatted_s method a more appropriate option. You can use the built-in formats:

date.to_formatted_s(:short)
date.to_formatted_s(:long)

or, you can create your own formats, adding them to Date::DATE_FORMATS:

Date::DATE_FORMATS[:my_format] = '%a, %d %b %Y'
date.to_formatted_s(:my_format)

This will keep you from spreading formatting strings throughout your app.