Skip to content

Instantly share code, notes, and snippets.

@alterisian
Created July 1, 2010 17:26
Show Gist options
  • Save alterisian/460265 to your computer and use it in GitHub Desktop.
Save alterisian/460265 to your computer and use it in GitHub Desktop.
# Convience method for ordanalized_date_string
def ods( date, day_of_week=false )
return ordanalized_date_string( date, day_of_week )
end
# Returns date string in format '29th December, 2009' i.e. UK style
# use instead of date.to_s( %stuff %rndstuff %another )
def ordanalized_date_string( date, day_of_week=false )
date_str = "#{date.day.ordinalize} %B, %Y"
if day_of_week
date_str = "%a " + date_str
end
return date.strftime( date_str )
end
@alterisian
Copy link
Author

I put this together as strftime doesn't have ordinalized dates in i.e 1st, 2nd, 3rd, 4th rather than 1,2,3,4

It's currently in application_helper.rb for a rails app, but probably has a more appropiate place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment