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
nohayeye
source
to share
3 answers
You can use the method Date.parse
:
> Date.parse "Mar 31, 1999"
=> Wed, 31 Mar 1999
+8
alestanis
source
to share
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
knut
source
to share
To parse a wide range of date strings, chronic
0
DGM
source
to share