Forum: Ruby split string into words

95e2092707d6ee9e7634e169f713cc38?d=identicon&s=25 Jade CKS (kc_123)
on 2014-07-18 02:00
Hi I am new to Ruby
I am trying to split a string.
Example I have string 2013-12-01T00:00:00+11:00 and I only want to get
the date
I've been looking at the split() method but not sure what the delimiter
will be in this case ?? Can someone please help me here. Thanks
D9ebdcb66f1583378e6f72155db507e2?d=identicon&s=25 Hans Mackowiak (hanmac)
on 2014-07-18 13:01
why not using the time parse functions?

require "time"
Time.parse("2013-12-01T00:00:00+11:00").to_date.to_s #=> "2013-12-01"
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2014-07-18 15:08
Jade CKS wrote in post #1152740:
> Hi I am new to Ruby
> I am trying to split a string.
> Example I have string 2013-12-01T00:00:00+11:00 and I only want to get
> the date
> I've been looking at the split() method but not sure what the delimiter
> will be in this case ??

"2013-12-01T00:00:00+11:00".split('T')[0]
95e2092707d6ee9e7634e169f713cc38?d=identicon&s=25 Jade CKS (kc_123)
on 2014-07-21 00:47
Thank you Hans and Regis for your reply. I actually manage to get the
date using the slice() method
But I want to try the time parse function. Thanks for your help guys
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.