Askar
Askar

Reputation: 5854

Converting date format from 04/08/13 to 2013-04-08 in ruby

$ irb
1.9.3-p429 :001 > require 'date'
 => true 
1.9.3-p429 :002 > Date.strptime('04/08/13' , '%m/%d/%Y').strftime('%Y-%m-%d')
 => "0013-04-08" 

For some reason, for the year, instead of 2013 it's showing 0013 ? :)

Upvotes: 0

Views: 69

Answers (1)

megas
megas

Reputation: 21791

You have format with small mistake, it should be %m/%d/%y

Date.strptime('04/08/13', '%m/%d/%y').strftime('%Y-%m-%d') => "2013-04-08"

Upvotes: 3

Related Questions