Compare mm/dd/yy dates

Hi
i am trying to write script with needs to compare couple of dates
example :-

                                         Protection

Good [000001L5] [MSL001: 1] No 04/22/14 18:11:06

Good [A00033L5] [MSL001: 25] Yes 03/28/14 03:18:07
Good [A00084L5] [MSL001: 30] Yes 03/30/14 03:00:25

now i need to eject the tape which has longer Protection which is
“04/22/14”

now how i compare 04/22/14 from 03/28/14 and 03/30/14

Do i have to convert mm/dd/yy to Unix date then need to compare ? or
Ruby can company it as it is ??

Please advise.

Fosiul A. wrote in post #1140705:

Do i have to convert mm/dd/yy to Unix date then need to compare ? or
Ruby can company it as it is ??

irb(main):021:0> require ‘time’
=> true
irb(main):028:0> Time.parse(“03/03/14”)
=> 2003-03-14 00:00:00 +0100
irb(main):029:0> Time.parse(“14/03/30”)
=> 2014-03-30 00:00:00 +0100

So something like that should work :

File.read(filename).split(/\r?\n/).sort_by {|line|
d= line.scan(/\d\d/\d\d/\d\d/).first.scan(/\d\d/).reverse.join(’/’)
Time.parse( d )
}.last

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs