I am using ruby 1.9.3
and want to get Date or Time
object from 'mm/dd/yyyy
' date format
string
Time.zone.parse("12/22/2011")
this is giving me *** ArgumentError Exception: argument out of range
Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Return: given representation of date and time, and creates a DateTime object.
Two steps: You need to convert your string into Date object. For that, use Date#strptime . You can use Date#strftime to convert the Date object into preferred format.
require 'Date' my_date = Date.strptime("12/22/2011", "%m/%d/%Y")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With