I have a selection of dates:
2015-09-25T11:08:00
2015-09-25T11:42:00
2015-09-25T17:02:00
2015-09-25T17:02:00
2015-09-28T13:09:00
How would i get the most recent date from this selection. I was trying to use
@messagedaterows.max {|obj| @message_thread_ID }
2.0.0p353 :005 > test
=> [2015-09-28 17:36:51 +0200, 2015-09-27 17:36:51 +0200]
2.0.0p353 :006 > test.sort
=> [2015-09-27 17:36:51 +0200, 2015-09-28 17:36:51 +0200]
2.0.0p353 :007 > test.sort.first
=> 2015-09-27 17:36:51 +0200
2.0.0p353 :008 > test.sort.last
=> 2015-09-28 17:36:51 +0200
You don't need complex logic for this.
Simply:
dates.max # => 2015-09-28 13:09:00
Even if they are strings this should work:
dates.max # => "2015-09-28T13:09:00"
The oldest date is also the minimal date . Therefore I would write something like this:
dates = options['Messages'].map { |entry| entry["Date"] }
dates.min
#=> 2015-09-25T11:08:00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.