From: Paul Date: 2011-06-07T23:48:25+09:00 Subject: Re: Ruby 1.9 Time parse question Hello Robert, thank you for the reply. I played with Date.strptime but it seems to ignore the time stamps. I need to use the time stamps to sort the records correctly. My current code joins the date and time and parses them together using the Time library so that it can sort it based on date+time stamp. Is there a way I can use the Date parser so that it factors in the date +time? (if there is, I haven't figured it out yet) Thanks. Paul. (I wish I could specify format for the Time parsing like I can with Date parsing) On Jun 7, 10:25 am, Robert Klemme wrote: > > > The line that is breaking is: > >> data_array.sort! { |a,b| Time.parse( b[1]+' '+b[2] ) <=> Time.parse( a[1]+' '+a[2] ) } > > > > the data is an AoA and looks like: > > data_array = [ ['1', '04/14/2011', '10:00 am', 'foo'], > >  ['2', '04/18/2011', '03:30 pm', 'bar'], > >  ['3', '04/18/2011', '11:15 am', 'baz']] > > > => so I expect the elements to resort as: 1, 3, 2. > > > You should give the format explicitly: > > 16:22:52 ~$ allruby -r date -e 'puts Date.strptime("04/14/2011", "%m/%d/%Y")' > CYGWIN_NT-5.1 padrklemme2 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin > ======================================== > ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] > 2011-04-14 > ======================================== > ruby 1.9.2p180 (2011-02-18 revision 30909) [i386-cygwin] > 2011-04-14 > ======================================== > jruby 1.6.1 (ruby-1.8.7-p330) (2011-04-12 85838f6) (Java HotSpot(TM) > Client VM 1.6.0_25) [Windows XP-x86-java] > 2011-04-14 > ======================================== > jruby 1.6.1 (ruby-1.9.2-p136) (2011-04-12 85838f6) (Java HotSpot(TM) > Client VM 1.6.0_25) [Windows XP-x86-java] > 2011-04-14 > ======================================== > > > Kind regards > > robert >