String by date in Ruby

I have many many string values ​​that look like "March 31st 1999".

Is there an easy way to get this string format to Ruby date?

+3


source to share


3 answers


You can use the method Date.parse

:



> Date.parse "Mar 31, 1999"
=> Wed, 31 Mar 1999 

      

+8


source


You can use Date.parse

. For more complex date strings, you can use strptime

:

require 'date'
puts Date.strptime('Mar 31, 1999', '%b %d, %Y') #->1999-03-31

      



strptime

is the opposite strftime

+2


source


To parse a wide range of date strings, chronic

0


source







All Articles