Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the newest and oldest date from a list - Ruby

I have an array of Ruby Date objects. How can I find the newest datetime and the oldest datetime?

like image 399
user94154 Avatar asked Oct 28 '09 02:10

user94154


2 Answers

date_array.min # => Oldest
date_array.max # => Most recent
like image 180
Baldu Avatar answered Oct 10 '22 19:10

Baldu


oldest, newest =  date_array.minmax
like image 31
steenslag Avatar answered Oct 10 '22 19:10

steenslag