sameera207
sameera207

Reputation: 16629

Converting string to Ruby datetime

I have the following string as a date

Thu 17 Jan

I want to convert this to a Ruby date time object (to save in the database). I have tried Chronic, but without luck.

Upvotes: 2

Views: 3529

Answers (2)

Mohammad Sadiq Shaikh
Mohammad Sadiq Shaikh

Reputation: 3200

You may also use:

 s = 'Thu 17 Jan'

 date = DateTime.parse(s)

Upvotes: 2

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230531

No need for chronic. Simple Date will do.

require 'date'

s = 'Thu 17 Jan'

Date.parse(s) # => #<Date: 2013-01-17 ((2456310j,0s,0n),+0s,2299161j)>

Upvotes: 2

Related Questions