2

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.

    2 Answers 2

    2

    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)> 
    2
    • require 'date' is not necessary in Rails.CommentedJan 18, 2013 at 5:26
    • Ah, indeed, he uses rails. Anyway, it won't hurt.CommentedJan 18, 2013 at 5:28
    2

    You may also use:

     s = 'Thu 17 Jan' date = DateTime.parse(s) 
    1
    • 1
      thanks for the answer this works. (Sorry I had select the Sergio's answer as correct as is the first one to post)CommentedJan 18, 2013 at 5:38

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.