Literary solution:
date.gsub(/(.{10}).*/, '\1')
date.gsub(/\s.*/, '')
date[0, 10]
Best solution: consider it as a DateTime object - then you can format it as you like:
date = DateTime.now
date.strftime("%m-%d-%Y")
date.strftime("%d-%m-%Y")
source
share