Not necessary for this particular string format, but best string to time parsing utility I know is Chronic which is available as a gem and works for about 99.9% of usecases for human formatted dates/times.
If you have control over the format of the date in the string, then Date.parse works fine internationally with strings in YYYY-MM-DD (ISO 8601) format:
I find this approach simpler since it avoid having to specify the date format for the parser:
You can use Time#parse.
However, because Ruby could parse the date as "MM-DD-YYYY", the best way is to go with DateTime#strptime where you can specify the input format.
Alternatively
Date#strptime(str, format)
.Like this You can get time Object from a string like this:
But Ruby parsing this as a Date!
So you can use the column as a string.
And you can assign string object to the attribute,
And parse the string for getting time object,
Not necessary for this particular string format, but best string to time parsing utility I know is Chronic which is available as a gem and works for about 99.9% of usecases for human formatted dates/times.
If you have control over the format of the date in the string, then
Date.parse
works fine internationally with strings inYYYY-MM-DD
(ISO 8601) format: