Skip to content

Instantly share code, notes, and snippets.

@tfe
Created February 28, 2011 23:46
Show Gist options
  • Save tfe/848294 to your computer and use it in GitHub Desktop.
Save tfe/848294 to your computer and use it in GitHub Desktop.
Ruby function to remove leading zeros (useful with strftime, place in application helper in Rails)
# Ruby function to remove leading zeros.
# Just put an asterisk (*) in front of any possible leading zero you want to remove.
# http://www.nullislove.com/2007/05/16/time-for-strftime/
def strip_zeros_from_date(marked_date_string)
marked_date_string.gsub('*0', '').gsub('*', '') unless marked_date_string.nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment