f



how do i convert this comma delimited string to date object?

I have a string with date and time that are comma delimited in this format. how do I convert it to date object?
2013-10-02, 4:30am
0
Junkone
9/2/2016 4:48:28 PM
comp.lang.ruby 48885 articles. 0 followers. Post Follow

3 Replies
571 Views

Similar Articles

[PageSpeed] 39

Junkone <junkone1@gmail.com> writes:

>I have a string with date and time that are comma delimited in this format. how do I convert it to date object?

DateTime.strptime('2013-10-02, 4:30am', '%Y-%m-%d, %H:%M%p')
0
Hasan
9/2/2016 6:19:31 PM
W dniu 2016-09-02 o 18:48, Junkone pisze:
> I have a string with date and time that are comma delimited in this format. how do I convert it to date object?
> 2013-10-02, 4:30am
> 

2.2.0 :008 > require 'time'
 => true
2.2.0 :012 > Date.parse('2013-10-02, 4:30am')
 => #<Date: 2013-10-02 ((2456568j,0s,0n),+0s,2299161j)>

0
jacki
9/6/2016 7:12:48 AM
On Friday, September 2, 2016 at 10:18:36 PM UTC+5:30, Junkone wrote:
> I have a string with date and time that are comma delimited in this format. how do I convert it to date object?
> 2013-10-02, 4:30am

Use Time.parse instead of the date parse.
require 'time'
Time.parse('2013-10-02, 4:30am') 

0
pratap477
10/21/2016 10:08:32 AM
Reply: