Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. splitting an array of strings which contain dates into date order
  2. ["09/Feb/2012:12:56:40.009+0000 13894 10.0.0.1",
  3. "09/Feb/2012:14:45:03.829+0000 12951 10.0.0.1",
  4. "09/Feb/2012:15:13:07.722+0000 3812 10.0.0.1",
  5. "09/Feb/2012:15:18:47.813+0000 50290 10.0.0.1",
  6. "09/Feb/2012:15:18:55.430+0000 2796 10.0.0.1",
  7. "09/Feb/2012:16:02:13.494+0000 5193 10.0.0.1",
  8. "09/Feb/2012:16:17:18.661+0000 4523 10.0.0.1",
  9. "09/Feb/2012:16:59:50.671+0000 9764 10.0.0.1",
  10. "09/Feb/2012:17:07:55.129+0000 3944 10.0.0.1"]
  11.        
  12. require 'date'
  13. a.max_by{|e| DateTime.strptime(e.split(' ').first, '%d/%b/%Y:%H:%M:%S.%L%z')}
  14. #=> "09/Feb/2012:17:07:55.129+0000 3944 10.0.0.1"
  15.        
  16. values = #your array of strings
  17. latest_date = values.map{|d| d.split(' ')[0]}.sort.last